Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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 !!

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-15-2013
Registered User
 
Join Date: Oct 2011
Posts: 29
Thanks: 23
Thanked 0 Times in 0 Posts
Formatting the file using pattern

Hi,

Please suggest the suitable command for my below requirement.

I have a file with greater than symbol (>) in many places in a file.
For example,

Code:
abcd>drfg>gdh

i want the output file like,

Code:
abcd>
drfg>
gdh>

Please suggest. Thanks.

Last edited by vbe; 02-15-2013 at 10:40 AM.. Reason: code tags please for your data or code
Sponsored Links
    #2  
Old 02-15-2013
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,490
Thanks: 166
Thanked 810 Times in 779 Posts

Code:
awk -F'>' '{$0=$0">"}{$1=$1; OFS=FS RS}1' file

The Following User Says Thank You to Yoda For This Useful Post:
rbalaj16 (02-15-2013)
Sponsored Links
    #3  
Old 02-15-2013
Registered User
 
Join Date: May 2012
Posts: 655
Thanks: 38
Thanked 170 Times in 157 Posts
With GNU/Posix awk,
linefeed after each ">"

Code:
awk 'BEGIN {FS=">"; OFS=FS RS} NF>1 {$1=$1} 1' file

Adding an extra ">"

Code:
awk 'BEGIN {FS=">"; OFS=FS RS} NF>1 {$NF=$NF FS} 1' file


Last edited by MadeInGermany; 02-15-2013 at 12:47 PM..
The Following User Says Thank You to MadeInGermany For This Useful Post:
rbalaj16 (02-15-2013)
    #4  
Old 02-15-2013
Registered User
 
Join Date: Oct 2011
Posts: 29
Thanks: 23
Thanked 0 Times in 0 Posts
Thanks all. it works fine.
Sponsored Links
    #5  
Old 02-15-2013
Registered User
 
Join Date: Oct 2010
Location: Southern NJ, USA (Nord)
Posts: 3,936
Thanks: 8
Thanked 484 Times in 464 Posts
In sed, very simple (but extra linefeed for > at end of line):
Code:
sed 's/>/>\
/g'

The Following User Says Thank You to DGPickett For This Useful Post:
MadeInGermany (02-16-2013)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search for a pattern in a String file and count the occurance of each pattern swayam123 Shell Programming and Scripting 4 11-06-2012 02:27 AM
Formatting file data to another file (control character related) hk6279 Shell Programming and Scripting 3 09-24-2012 03:17 AM
AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2 right_coaster Shell Programming and Scripting 9 10-06-2011 11:54 AM
Searching a pattern in file and deleting th ewhole line containing the pattern Shazin Shell Programming and Scripting 1 07-24-2009 11:27 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 02:41 PM



All times are GMT -4. The time now is 01:44 AM.