![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help me with parsing this file | eamani_sun | Shell Programming and Scripting | 2 | 05-16-2008 04:39 PM |
| awk and file parsing | devtakh | Shell Programming and Scripting | 4 | 05-06-2008 12:13 PM |
| Parsing a csv file | chiru_h | Shell Programming and Scripting | 6 | 02-12-2008 09:33 AM |
| File Parsing | jsusheel | Shell Programming and Scripting | 5 | 09-25-2007 11:25 AM |
| parsing file through awk | bbeugie | Shell Programming and Scripting | 13 | 08-22-2006 02:21 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Parsing a file
Hi,
Please help in parsing the following file and write separate files by parsing the file for the new file's content. Main File: ------------ BEGIN FileName: FirstFile.txt Content of the File Start AAAAAAAA BBBBBBB Content of the File End END BEGIN FileName: SecondFile.txt Content of the File Start CCCCCC DDDDDD Content of the File End END BEGIN FileName: ThirdFile.txt Content of the File Start EEEEEEE FFFFFFFF Content of the File End END BEGIN FileName: FourthFile.txt Content of the File Start YYYYYYYY ZZZZZZZZ Content of the File End END OUTPUT: Four files with the file names FirstFile.txt,SecondFile.txt,ThirdFile.txt and FourthFile.txt and content of the files will be between BEGIN and END except FileName eg: FirstFile.txt: ################## Content of the File Start AAAAAAAA BBBBBBB Content of the File End ################## Thanks in Advance |
|
||||
|
Hope this Should Work!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#!/usr/bin/ksh i=1 j=1 cat samp | while read line do val="END" value="BEGIN" if [ $j -le 7 ] then if [[ $line != $val && $line != $value ]] then echo $line echo $line >> File$i.txt j=`expr $j + 1` fi if [ $j -eq 7 ] then j=0 i=`expr $i + 1` fi fi done Regards, Anand |
|
||||
|
Quick Question
Hi Shamrock & Anand,
I am trying to parse the similar (below mentioned sample.txt) file using the following script. But I am having the following issue: 1. Whitespaces of the file are not maintained. 2. Text (****************************************) is not getting printed.Its getting translated to the script file name. Script: #!/usr/bin/sh i=1 cat sample.txt | while read line do var1="END" var2="BEGIN" toPrint=`echo $line | cut -c1-7` toPrintText=`echo $line | cut -c8-` elif [[ $toPrint == 'TOPRINT' ]] then echo toPrintText elif [[ $line != $var1 && $line != $var2 ]] then echo $line >> File$i.txt elif [[ $line == $var1 ]] then i=`expr $i + 1` fi done ========= sample.txt ========= BEGIN First File Content Starts here **************************************** Something or the other here TOPRINT=This is the text to print on the consolee.... This is the end of the File content END BEGIN Second File Content Starts here **************************************** Something or the other here TOPRINT=This is the text to print on the consolee.... This is the end of the File content END BEGIN Third File Content Starts here **************************************** Something or the other here TOPRINT=This is the text to print on the consolee.... This is the end of the File content END Appreciate your response! Thanks |
|
||||
|
Quote:
Quote:
Code:
while read line do : ... done <sample.txt Quote:
Code:
var1="END" var2="BEGIN" toPrint="`echo "$line" | cut -c1-7`" toPrintText="`echo "$line" | cut -c8-`" elif [[ "$toPrint" == 'TOPRINT' ]] then echo "$toPrintText" Your "elif" seems to be missing the initial "if" but that's trivial, of course. Last edited by era; 03-24-2008 at 03:28 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|