How to add a return after a special pattern?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add a return after a special pattern?
# 1  
Old 10-12-2011
Data How to add a return after a special pattern?

Hello
I'm new to Solaris

I have a file have things like these

Code:
PATTERN12345678
PATTERN12345678PATTERN87654321
PATTERN12345678 PATTERN87654321

i hope i could change to this format
Code:
PATTERN12345678
PATTERN12345678
PATTERN87654321
PATTERN12345678
PATTERN87654321

I've tried grep sed and tr. but failed. could someone give me a example?
# 2  
Old 10-12-2011
Code:
$ sed 's,PATTERN,|PATTERN,2' infile | tr '|' '\n'
PATTERN12345678
PATTERN12345678
PATTERN87654321
PATTERN12345678
PATTERN87654321
$

# 3  
Old 10-12-2011
Code:
sed '/PATTERN12345678[^$]/{s/\(PATTERN12345678[ ]*\)\(.*\)/\1\n\2/g}' input_file

--ahamed

Last edited by ahamed101; 10-12-2011 at 02:58 AM..
# 4  
Old 10-12-2011
Code:
awk -F"PATTERN" '{for(i=1;i<=NF;i++){printf $i!=""?FS $i"\n":x}}' filename

If running on SunOS or Solaris platform, use "nawk" or "/usr/xpg4/bin/awk" instead of "awk"
# 5  
Old 10-15-2011
Thanks you
It works!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace Pattern with another that has Special Characters

Hello Team, Any help would be much appreciated for the below scenario: I have a sed command below where I am trying to replace the contents of 'old_pkey' variable with 'new_pkey' variable in a Soap request file (delete_request.txt). This works fine for regular string values, but this new_pkey... (8 Replies)
Discussion started by: ChicagoBlues
8 Replies

2. UNIX for Dummies Questions & Answers

Return alias with pattern

hello all, i have ids repeated with alias names starting with different patterns like 'ab' , 'fg' etc...sometimes the same pattern names are repeated with the same ids like id=1 has names ab1 as well as ab3. Lookup.txt name id ab1 1 fg22 1 ab3 1 er2 1 fgh1 1 fg21 2 ab2 2 ab31 2... (8 Replies)
Discussion started by: jalaj841
8 Replies

3. Shell Programming and Scripting

Grep correct pattern with special character and variables

cat file time="north_south_east_west_08:00" location="A" start="left" status="ok" end="north" time="north_south_east_west_12:00" location="C" start="right" status="ok" end="south" time="north_south_east_west_23:00" location="G" start="left" status="ok" end="east"... (7 Replies)
Discussion started by: ctphua
7 Replies

4. Shell Programming and Scripting

Pattern match exclusive return pattern/variable

I have an application(Minecraft Server) that generates a logfile live. Using Crontab and screen I send a 'list' command every minute. Sample Log view: 2013-06-07 19:14:37 <Willrocksyea1> hello* 2013-06-07 19:14:41 <Gromden29> hey 2013-06-07 19:14:42 Gromden29 lost connection:... (1 Reply)
Discussion started by: gatekeeper258
1 Replies

5. Shell Programming and Scripting

Grep special pattern in 3rd column

I have a file (test.dat) that has this pattern: 1000 000001 (92.431343802235503, 90.0) 1000 000002 (87.568656197764497, 80.0) 1000 000003 (150.75815307316083, 150.0) 1000 000004 (29.241846926839159, 20.0) 1000 000005 (110.02128542766, 110.0) 1000 000006 (69.978714572339996, 60.0) 1000... (8 Replies)
Discussion started by: kayak
8 Replies

6. Shell Programming and Scripting

a cut-command or special format pattern in awk

Hi i read data with awk, 01.07.2012 00:10 227.72 247.50 1.227 1.727 17.273 01.07.2012 00:20 237.12 221.19 2.108 2.548 17.367 01.07.2012 00:30 230.38 230.34 3.216 3.755 17.412 01.07.2012 00:40 243.18 242.91 4.662 5.172 17.328 01.07.2012 00:50 245.58 245.41 5.179 5.721 17.128... (3 Replies)
Discussion started by: IMPe
3 Replies

7. Shell Programming and Scripting

awk search pattern with special characters passed from CL

I'm very new to awk and sed and I've been struggling with this for a while. I'm trying to search a file for a string with special characters and this string is a command line argument to a simple script. ./myscript "searchpattern" file #!/bin/sh awk "/$1/" $2 > dupelistfilter.txt sed... (6 Replies)
Discussion started by: cue
6 Replies

8. Shell Programming and Scripting

sed delete pattern with special characters

Hi all, I have the following lines <b>A gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) <b>B gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) <b>J gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) and I would like to... (5 Replies)
Discussion started by: stinkefisch
5 Replies

9. Shell Programming and Scripting

pattern matching on any special character in Unix

Hi, I have field in a file which would come with any special character, how do i check that field? Eg: @123TYtaasa>>>/ 131dfetr_~2 In the above example, how do I add pattern for any special character on the keyboard. Thanks (3 Replies)
Discussion started by: techmoris
3 Replies

10. Shell Programming and Scripting

Help with pattern search and return

I would like to write a script which will read a file containing a list of filenames of the format as shown below : /usr/local/packages/runcmdlinetool /home/john.doe/sdfsdf/sdfsdfsd/sdfsdf/sdfsdfTemplates.xml /usr/local/bin/gtar... (4 Replies)
Discussion started by: inditopgun
4 Replies
Login or Register to Ask a Question