text parsing querry


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting text parsing querry
# 1  
Old 06-13-2008
text parsing querry

$ A=/t1/bin/f410pdb oIFS=$IFS IFS=/
$ set -- $A
$ IFS=$oIFS

$ echo $2
t1
$ echo $3
bin
$ echo $4
f410pdb

can any one please explain me what is done with IFS[bold lines] and how it is working internally ...i am interested to know in depth
# 2  
Old 06-13-2008
The IFS variable is the "internal field separator". It determines how the shell tokenizes arguments. For example, then you invoke a program with progname arg1 arg2 arg3, and also when you do set -- $variablename, the shell's argument list $* (and also $1, $2, $3 etc) is populated with the results of tokenizing the arguments according to the setting in IFS. Nornally, it is configured to split the input into tokens on whitespace, so the arguments to progname are arg1, arg2, and arg3, but you can change it to basically anything you like.

That's what this script does. It sets IFS to a slash, and then uses set -- $A to split the value of $A into separate tokens, using the slash as the token delimiter. So the end result is that $1 contains nothing (the "emptyness" before the first slash in $A), $2 contains the string between the first two slashes in $A, $3 contains the string between the next two slashes, etc; and also the contents of $* and $@ are updated to contain the results from the tokenization.

A helper variable oIFS is simply used to remember and finally restore the previous contents of IFS. This is just a regular variable; you can call it anything you like.
# 3  
Old 06-13-2008
Wow! This is great information era!!

Thanks!
nua7
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Text parsing

Hi All! Is it possible to convert text file: to: ? (6 Replies)
Discussion started by: y77
6 Replies

2. Shell Programming and Scripting

Parsing blocked text

I do have a flat text file that are divided into blocks. Each block is demimited by '='. I would like to parse certain numbers and letters. This is the format of the file I have. It has thousands of such blocks >A B 1, 100 TTTT 100 95 >C D 1, 95 GHJKL = >A B 1, 72 GHUJKLO 72 84 >C D... (3 Replies)
Discussion started by: Kanja
3 Replies

3. Shell Programming and Scripting

Parsing text file

Hi Friends, I am back for the second round today - :D My input text file is this way Home friends friendship meter Tools Mirrors Downloads My Data About Us Help My own results BLAT Search Results ACTIONS QUERY SCORE START END QSIZE IDENTITY CHRO STRAND ... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

4. Shell Programming and Scripting

Need help parsing a text file

I have a text file: router1#sh ip blah blah | incl --- Gi2/8 10.60.4.181 --- 10.60.123.175 11 0000 0000 355K Gi2/8 10.60.83.28 --- 224.10.10.26 11 F9FF 3840 154K Gi2/8 10.60.83.198 --- ... (1 Reply)
Discussion started by: streetfighter2
1 Replies

5. Shell Programming and Scripting

Parsing text

Hello all, I have some text formatted as follows Name: John doe Company: Address 1: 7 times the headache Address 2: City: my city State/Province: confusion Zip/Postalcode: 12345 and I'm trying to figure out how I could extract the data after the colon so that the result would be ... (6 Replies)
Discussion started by: mcgrailm
6 Replies

6. Shell Programming and Scripting

Parsing text from file

Any ideas? 1)loop through text file 2)extract everything between SOL and EOL 3)output files, for example: 123.txt and 124.txt for the file below So far I have: sed -n "/SOL/,/EOL/{p;/EOL/q;}" file Here is an example of my text file. SOL-123.go something goes here something goes... (0 Replies)
Discussion started by: ndnkyd
0 Replies

7. Shell Programming and Scripting

Text File Parsing

Hey Guys.I am a newbie on Bash Shell Scripting and Perl.And I have a question about file parsing. I have a log file which contains reports about a communication device.I need to take some of the reports from the log file.Its hard to explain the issue.but shortly I can say that, the reports has a... (2 Replies)
Discussion started by: Djlethal
2 Replies

8. Shell Programming and Scripting

parsing output from SQL querry

Hi all I have this output in a variable called ...yes $OUTPUT :-) original...huh these are tablespaces in an Oracle db how do I get this into another variable in two columns so I can do a check on the numbers (space left) SYSTEM 290; USERS 19; UNDOTBS1 1863; DATA 5982; SYSTEM 290; USERS... (7 Replies)
Discussion started by: ludvig
7 Replies

9. HP-UX

querry on du

hi all, To summerize disk usage in human readable format we have "du -h" in linux,which gives the disk usage in MBs. do we have something similar in HP-UX ? thanks, amit (4 Replies)
Discussion started by: amit4g
4 Replies

10. UNIX for Dummies Questions & Answers

Text parsing question

How would I split a file based on the location of a string, basically I want all entries above the string unix in this example 1 2 3 4 unix 5 6 7 Thanks, Chuck (3 Replies)
Discussion started by: 98_1LE
3 Replies
Login or Register to Ask a Question