PDA

View Full Version : Bash - parsing text ? (beginner)



bubbaspam
July 26th, 2011, 09:58 PM
Sorry, but I am very new to this and haven't been able to figure out how to parse a simple text file (dummy.txt).

Example:
email - header gibberish
http:/www.somewhere.com/xyzdir/XXXXXXXXX/?mode=desktop
other random text

I need to set a variable ($id) to XXXXXXXXXX

Thanks for any help!

mikejonesey
July 26th, 2011, 10:12 PM
start;

cat moomoo.txt

email - header gibberish
http:/www.somewhere.com/xyzdir/XXXXXXXXX/?mode=desktop
other random text

grep www.somewhere.com

http:/www.somewhere.com/xyzdir/XXXXXXXXX/?mode=desktop

sed 's/\//g'

http: www.somewhere.com xyzdir XXXXXXXXX ?mode=desktop

awk '{print $4}'

XXXXXXXXX

would need more data to properly tell you though... (don't know what to filter for or on...)

mikejonesey
July 26th, 2011, 10:14 PM
or;


cat blabla.txt | grep ^http | cut -d "/" -f 4

ps... would still need more data to confirm... :)