Move a text to next line in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move a text to next line in a file
# 1  
Old 05-14-2013
Move a text to next line in a file

Hi ,

I need your help for the below issue.

I have a file which has data as below


Code:
An error came (/u01/app/12.csv)
pkg1.func1: detail s 1111-->pkg1.func1: detail s 2222-->

Now pkg1.func1: .... --> can come multiple times in the second line.
I need to arrange the data in the below way for the file.

Code:
An error came (/u01/app/12.csv)
pkg1.func1: detail s 1111
pkg1.func1: detail s 222

The above thing will happen for any number of occurrences of pkg1.func1: .... --> text.

Thanks in advance.

Last edited by joeyg; 05-14-2013 at 11:14 AM.. Reason: Please wrap commands and data inside CodeTags
# 2  
Old 05-14-2013
So, essentially you want to change
"-->" to a new-line character (carriage return/line feed)
???
# 3  
Old 05-14-2013
check this one
Code:
 
sed 's/-->/\n/g' input_file.txt

# 4  
Old 05-14-2013
Thanks for the reply.
Yes I want this thing along with
Code:
pkg1.func1: detail s 1111
pkg1.func1: detail s 222

which means pkg1.func1: will be coming everytime .

Last edited by Scrutinizer; 05-14-2013 at 12:02 PM.. Reason: closing code tag
# 5  
Old 05-14-2013
An awk approach:
Code:
awk '/pkg1\.func1/{gsub("-->",RS)}1' file

This User Gave Thanks to Yoda For This Post:
# 6  
Old 05-14-2013
Quote:
Originally Posted by Yoda
An awk approach:
Code:
awk '/pkg1\.func1/{gsub("-->",RS)}1' file

Thanks for your help. It worked.
Can you please explain me the code as I'm not very much efficient in awk.
# 7  
Old 05-14-2013
Code:
awk '
        /pkg1\.func1/ {                 # Check if pattern: pkg1.func1 present in current record.
                gsub ("-->", RS)        # Global Substitute "-->" with RS (RS is a special awk variable, by default a newline)
        }
        1                               # 1 == true (if true, the default awk action is to print current record)
' file

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move a line to top of the file

Hi, I have a following file and it has only one occurrence of line that says "Output view:". It could be in middle somewhere ( i don't know the exact location ). I want to move it as the first line of the file. Input AAA BBBB CCCC Output view: XXXX YYYY ZZZZ Output should be: Output... (13 Replies)
Discussion started by: jakSun8
13 Replies

2. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

3. Shell Programming and Scripting

move string in a text file

Hi all! I need some help in changing a text file. I have the following text file: 1,050406259214736,00010,5000,MZM,V050,20131231,EMIG 2,Available,20061126T10:40:15,vs,, 2,Used,20110813T12:32:35,,825351585,1411012901443027 1,050410256649750,00010,5000,MZM,V050,20131231,EMIG ... (2 Replies)
Discussion started by: fretagi
2 Replies

4. Shell Programming and Scripting

awk - if field is empty, move line to new file

I have a script with this statement: /usr/xpg4/bin/awk -F"" 'NR==FNR{s=$2;next}{printf "%s\"%s\"\n", $0, s}' LOOKUP.TXT finallistnew.txt >test.txt I want to include logic or an additional step that says if there is no data in field 3, move the whole line out of test.txt into an additional... (9 Replies)
Discussion started by: scriptr2be
9 Replies

5. Shell Programming and Scripting

Move a line to end of file

Can somebody help me with a script .... Read a file /etc/inittab find the string starting with rcml and move it entirely towards the end of file. rcml:2:once:/usr/sni/aix52/rc.ml > /dev/console 2>&1 I basically want to change the startup sequence. (2 Replies)
Discussion started by: imanuk2007
2 Replies

6. UNIX for Dummies Questions & Answers

Using grep to move files that contain a line of text

I have a folder with about 4000 files in it. I need to extract the files that contain a certain line of text to another directory. for example files with 'ns1.biz.rr.com' need to be extracted to the directory above or some other directory. I tried using the following but was not successful. (6 Replies)
Discussion started by: spartan22
6 Replies

7. Shell Programming and Scripting

Script to move the first line of a file to the end

I'm rather new to scripting, and despite my attempts at finding/writing a script to do what I need, I have not yet been successful. I have a file named "list.txt" of arbitrary length with contents in the following format: /home/user/Music/file1.mp3 /home/user/Music/file2.mp3... (21 Replies)
Discussion started by: Altay_H
21 Replies

8. Shell Programming and Scripting

how to move the line after a certain pattern in the file

Hi, I have a file called /bb/bin/rstrt. I need to move the line/entry "ccpm_load_shared_memory" after the entry "initcorp". The problem is that there are several entries for "initcorp" in this file and I need the entry to be moved only after the first instance of "initcorp" Is there a way... (5 Replies)
Discussion started by: aoussenko
5 Replies

9. Programming

how to move file pointer to a particular line in c

Hello experts, I ve a text file I want to go to particular line . what is the best way to do this in c ? I am tried as follows fseek ( fh, pos, SEEK_SET); but this functions moves the file pointer according to a number of bytes. Unfortunately I don't know the exact byte... (7 Replies)
Discussion started by: user_prady
7 Replies

10. Shell Programming and Scripting

script to move text in file?

ok i asked around to a few ppl and they said to use sed or awk to do what i want.. but i cant figure out how to use it like that.. anyway i have a text file that is 10k lines long.. i need to move text from the end of a line after the ? and move it to the front of the line then add a | after it.... (3 Replies)
Discussion started by: wckdkl0wn
3 Replies
Login or Register to Ask a Question