script to find backshash and place the content in next line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to find backshash and place the content in next line
# 1  
Old 02-16-2012
script to find backshash and place the content in next line

Hi All,

I am new to the forum and scripting...Can someone help me with a code..

My input file will be like
Code:
$cat first
aa a\b     bb\ccccc\ddd
ee*e\fff\ggg

output should be
Code:
aa a\
b     bb\
ccccc\
ddd
ee*e\
fff\
ggg

I tried with
Code:
cat first | awk '{ gsub( /\\/, "/\\/" ); print }' > second
tr -s "/\\/" '\n' < second > outfile3

but i am not able to get the required one..

i am getting like below
Code:
aa a
\
b     bb
\
ccccc
\
ddd
ee*e
\
fff
\
ggg

Thanks in advance
Madhan M

Last edited by Franklin52; 02-17-2012 at 03:08 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-16-2012
You get a useless use of cat award.

Code:
sed 's/\\/\\\n/g' filename

# 3  
Old 02-16-2012
thanks a lot for your support.. but i am not getting the required output.. i am getting like
Code:
$sed 's/\\/\\\n/g' first
aa a\nb bb\nccccc\nddd
ee*e\nfff\nggg


Last edited by Franklin52; 02-17-2012 at 03:07 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 02-16-2012
You have a mouldy old version of sed which doesn't understand \n. You'll have to give it a real newline instead.

Code:
sed 's/\\/\\
/g' filename

# 5  
Old 02-16-2012
Assuming # is not used in your initial file you can for example :
Code:
sed 's/\\/\\#/g' first | tr '#' '\n'

This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 02-17-2012
Great thanks a lot.. it works very well...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Remove new line for a particular place

Hello All, I have a text file which gets uploaded to tables using shells script. However before running that script I need to alter it, like in the below I have to firstly find the word 1234 and remove the new line from end of it. 1234,5678,fasfasasfsadf abc changes to... (11 Replies)
Discussion started by: Sandeep_sandy
11 Replies

2. Shell Programming and Scripting

Find for line with not null values at nth place in pipe delimited file

Hi, I am trying to find the lines in a pipe delimited file where 11th column has not null values. Any help is appreciated. Need help asap please. thanks in advance. (3 Replies)
Discussion started by: manikms
3 Replies

3. Shell Programming and Scripting

Find regex, place on individual lines and insert blank line before

Hello, I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance. Contents of infile: Test this 1... Test this 2... Test this 3... Test this 4... Test this... (2 Replies)
Discussion started by: deneuve01
2 Replies

4. Shell Programming and Scripting

cut the variable from the line and use it to find the file and read the content of that file

Hi, I am working on one script..I am having files in the below format file 1 (each line is separated with : delimeter) SPLASH:SPLASH:SVN CIB/MCH:MCH:SVN Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

5. Shell Programming and Scripting

script for inserting line at specific place in file

I use zentyal for my server admin, which is great but zentyal auto-generates config file on boot and hence overwrites any changes made directly to config files. In order to allow multiple user access to a MS ACCESS database, I need to customise the smb.conf file and add the following line to the... (9 Replies)
Discussion started by: barrydocks
9 Replies

6. Shell Programming and Scripting

Place 'find' results within TeX command

Hi, In an effort to collect all my .java-files and place them in a LaTeXfile (using the listings environment of latex), i tried to use ex. So what i have now is: find . -name "*\.java" > latex ex latex <<HERE %s/\(.*\)/\\lstinputlisting{\1} wq HERE So i try to escape the '\' with... (1 Reply)
Discussion started by: HannesBBR
1 Replies

7. Shell Programming and Scripting

Place variables at the beginning of each line

Hello all, I am very new to the shell scripting and I hope someone can help me with this. I have thousands of files with certain format of information and I need to do this for all my files. For each file, grab the numbers in the first and second rows and place them in the position 1 and 2... (8 Replies)
Discussion started by: GoldenFire
8 Replies

8. Shell Programming and Scripting

Perl Script - Print Content of next line

Good evening to you all perl experts I need your help I have a very simple script where I´m trying to print a line from status.dat file. The script will find the line containing "servicestatus", and I want to print the content of the next line. For example, the file contains this text:... (6 Replies)
Discussion started by: zarahel
6 Replies

9. Shell Programming and Scripting

Find a string and place two blank lines

Hi friends, I am looking for a line to find a particular string in my file and once found then replace with 2-3 blank lines before the string Example: aaa 11 bbb 1 2 3 aaa 22 bbb 4 5 6 Output (4 Replies)
Discussion started by: shaliniyadav
4 Replies

10. Shell Programming and Scripting

Getting the value of a line, that changes place

Hi I am trying to get the value of several results in a file called seq032.diag. The values I am looking for is down under Smooth Tracking nodes and is for g01r01 g02r01 s01t02 etc etc. The problem is that when I try to use look for text and tail etc, it works fine in one result file. In... (1 Reply)
Discussion started by: Navigatorchief
1 Replies
Login or Register to Ask a Question