Formatting the file using pattern | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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

Formatting the file using pattern

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-15-2013
rbalaj16 rbalaj16 is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 11 April 2013, 11:40 AM EDT
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 11:40 AM.. Reason: code tags please for your data or code
Sponsored Links
    #2  
Old 02-15-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 21 November 2014, 11:17 AM EST
Location: Galactic Empire
Posts: 3,389
Thanks: 235
Thanked 1,210 Times in 1,136 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
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 22 November 2014, 10:54 PM EST
Location: Simplicity
Posts: 2,053
Thanks: 134
Thanked 603 Times in 547 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 01:47 PM..
The Following User Says Thank You to MadeInGermany For This Useful Post:
rbalaj16 (02-15-2013)
    #4  
Old 02-15-2013
rbalaj16 rbalaj16 is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 11 April 2013, 11:40 AM EDT
Posts: 29
Thanks: 23
Thanked 0 Times in 0 Posts
Thanks all. it works fine.
Sponsored Links
    #5  
Old 02-15-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 21 November 2014, 7:36 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,522
Thanks: 8
Thanked 555 Times in 532 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
Closed Thread

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 03:27 AM
Formatting file data to another file (control character related) hk6279 Shell Programming and Scripting 3 09-24-2012 04: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 12:54 PM
Searching a pattern in file and deleting th ewhole line containing the pattern Shazin Shell Programming and Scripting 1 07-24-2009 12:27 PM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM



All times are GMT -4. The time now is 11:02 AM.