![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ls while read loop - internal read picking up wrong input | dkieran | Shell Programming and Scripting | 2 | 05-14-2007 12:02 PM |
| How to read a line and put it into 3 variables | Mandab | Shell Programming and Scripting | 8 | 04-20-2007 09:50 AM |
| is there any way to read a line twice in KSH | Srini75 | Shell Programming and Scripting | 6 | 01-24-2006 10:14 PM |
| How to read from a file line by line and do stuff | spaceship | Shell Programming and Scripting | 4 | 03-17-2005 06:47 PM |
| read vs line | kishorebabu | Shell Programming and Scripting | 2 | 10-31-2003 07:53 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi,
there is a text like this in text.txt DETAILS ( USERID, USERNM ) how to find the 'DETAILS (' and start to read next line until meet the char ')', when read next line i need to put the 'USERID' into a variable name to be use later thanks a lot ...please help |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Well what have you tried so far?
|
|
#3
|
|||
|
|||
|
below is what i tried so far, any good idea
hasDetail='FALSE' exec 4<$1 while read eachline <&4 do if [ "$eachline" == ")" ] then hasDetail='FALSE' fi if [ "$hasDetail" == "TRUE" ] then varnm=`echo $eachline | cut -f1 -d,` repnm=P`echo $varnm | cut -c 2-` sed 's/$varnm/$repnm/g' $1 > $1.$$ sed 's/$repnm/$repnm/g' $1.$$> $1 fi if [ "$eachline" == "DETAIL (" ] then hasDetail='TRUE' fi done |
|
#4
|
||||
|
||||
|
Quote:
Change the place of Code:
if [ "$eachline" == "DETAIL (" ]
then
hasDetail='TRUE'
fi
I dont find the approach you are using reliable, it will fail in the scenario where the data file has unmatched ")" rishi |
|
#5
|
||||
|
||||
|
If you are looking to extract only USERID check this out.
Code:
sh-2.05b$ echo "DETAILS (
USERID,
USERNM
)" | sed -n -e '/DETAILS.*/{
n
s#\(.*\)\,#\1#p
}'
vino |
|
#6
|
|||
|
|||
|
j=0;
foreach $curline (<FILE NAME>) { if j=0 { next if($cur_line !~ /DETAILS\(/); j=1; next; } if($cur_line !~ /\)/); { . . put your logic here... . } else { exit 1 } Last edited by rishchand; 09-21-2005 at 01:49 AM. Reason: here is the program in perl try this out... |
|
#7
|
|||
|
|||
|
one more way ...
echo "DETAILS ( USERID, USERNM )" | sed -ne 's/,$//p' |
|||
| Google The UNIX and Linux Forums |