![]() |
|
|
|
|
|||||||
| 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 |
| Adding Multiple Lines to Multiple Files | dayinthelife | Shell Programming and Scripting | 2 | 06-04-2008 08:50 AM |
| retrieved multiple lines on multiple places in a file | dala | Shell Programming and Scripting | 8 | 03-14-2008 12:28 PM |
| Help Needed : Split one big file to multiple files | monicasgupta | Shell Programming and Scripting | 5 | 03-03-2008 04:09 PM |
| Split a huge line into multiple 120 characters lines with sed? | jerome_1664 | Shell Programming and Scripting | 2 | 08-17-2006 09:03 AM |
| multiple pattern split in perl | umen | Shell Programming and Scripting | 3 | 07-31-2006 11:43 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Split data into multiple lines
All,
I have a requirement where I will need to split a line into multiple lines. Ex: Input: 2ABCDEFGH2POIYUY2ASDGGF2QWERTY Output: 2ABCDEFGH 2POIYUY 2ASDGGF 2QWERTY The data is of no fixed lenght. Only the lines have to start with 2. How can this be done. Thanks KP. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
nawk -v RS="2" 'length()==0{next}{print "2" $0}' <<EOF
2ABCDEFGH2POIYUY2ASDGGF2QWERTY EOF 2ABCDEFGH 2POIYUY 2ASDGGF 2QWERTY |
|
#3
|
||||
|
||||
|
Quote:
Code:
nawk -v RS="2" 'length()==0{next}{print "2" $0}' <<EOF
> aa2ABCDEFGH2POIYUY2ASDGGF2QWERTY
> EOF
2aa
2ABCDEFGH
2POIYUY
2ASDGGF
2QWERTY
Code:
echo 'aa2ABCDEFGH2POIYUY2ASDGGF2QWERTY' | nawk 'gsub("2", "\n2")' | sed '/^$/d'
aa
2ABCDEFGH
2POIYUY
2ASDGGF
2QWERTY
|
|
#4
|
|||
|
|||
|
Code:
echo "2ABCDEFGH2POIYUY2ASDGGF2QWERTY" | sed -e 's/2/\ 2/g' |
|
#5
|
||||
|
||||
|
Matrix,
Your 'sed' solution displays the first line as empty: Code:
2ABCDEFGH 2POIYUY 2ASDGGF 2QWERTY Code:
sed '/^$/d' Code:
echo "2ABCDEFGH2POIYUY2ASDGGF2QWERTY" | sed -e 's/\(.\)2/\1\ 2/g' Code:
2ABCDEFGH 2POIYUY 2ASDGGF 2QWERTY |
|
#6
|
|||
|
|||
|
Quote:
Sorry I didn't notice that. Thanks for correcting it ! |
|||
| Google The UNIX and Linux Forums |