![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help needed - ksh shell scripting | subbu | Shell Programming and Scripting | 5 | 02-15-2008 09:53 AM |
| SHell Scripting Help Needed | cskumar | Shell Programming and Scripting | 2 | 07-16-2006 10:55 PM |
| difference between AIX shell scripting and Unix shell scripting. | haroonec | Shell Programming and Scripting | 2 | 04-12-2006 05:12 AM |
| help needed in shell scripting......urgent | swamymns | Shell Programming and Scripting | 3 | 12-06-2005 08:10 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help needed - shell scripting
I have a file that has text in the format below
ABC / Some text / ABC / Some text / ABC / Some text / ABC / Some text / ABC / Some text / How can I seperate the text between a pair of 'ABC' into seperate files ??? any information would be of great help. Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Do you mean you want to create a file that is minus all the ABC's?
Code:
grep -v 'ABC' oldfile > newfile |
|
#3
|
|||
|
|||
|
no, if we consider the example ... i want to create five different files with the content of each coming from the text betweeen two consecutive 'ABC's
|
|
#4
|
|||
|
|||
|
Code:
#/bin/ksh
let filecnt=0
while read record
do
if [ `echo $record | grep -q '^ABC'` -ne 0 ] ; then
echo "$record" > newfile"$filecnt"
let filecnt=$filecnt + 1
fi
done < oldfile
|
|
#5
|
||||
|
||||
|
If same output can be achieved with sed?
Hi,
Out of interest, is possible to redirect the same output with sed to textfile.$count? using branching (b), hold space or whatsoever is available in sed to output different sections from one file to more than files? Regards, Tayyab |
|
#6
|
|||
|
|||
|
Thsi is gave an error, something regarding ' unary operators for -ne'
|
|
#7
|
||||
|
||||
|
Perhaps use awk...
Code:
$ < infile awk '/ABC/{c++; next} {print > "outfile." c}'
$ head outfile.*
==> outfile.1 <==
/ Some text /
==> outfile.2 <==
/ Some text /
==> outfile.3 <==
/ Some text /
==> outfile.4 <==
/ Some text /
==> outfile.5 <==
/ Some text /
|
||||
| Google The UNIX and Linux Forums |