move string in a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting move string in a text file
# 1  
Old 05-16-2012
move string in a text file

Hi all!

I need some help in changing a text file. I have the following text file:
Code:
  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,Available,20061126T10:40:15,vs,,
  2,Used,20110809T14:21:04,,825044142,1765121002150049
  1,050410256649751,00010,5000,MZM,V050,20131231,EMIG
  2,Available,20061126T10:40:15,vs,,

What I want is to move whatever is in front of digit 1 to be placed in front of word "Available".
For example the string "050406259214736" in line 1 should be moved to after word "Available" in line 2.
The number "050410256649750" in line 4 should be moved to after the word "Available" in line 5.

Whould that be possible?

FR
# 2  
Old 05-16-2012
Post desired output for this sample data.
# 3  
Old 05-16-2012
move string in a text file

original file:
Code:
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,Available,20061126T10:40:15,vs,,
  2,Used,20110809T14:21:04,,825044142,1765121002150049
  1,050410256649751,00010,5000,MZM,V050,20131231,EMIG
  2,Available,20061126T10:40:15,vs,,

target file:

Code:
1,00010,5000,MZM,V050,20131231,EMIG
  2,Available,050406259214736, 20061126T10:40:15,vs,,
  2,Used,20110813T12:32:35,,825351585,1411012901443027
  1,00010,5000,MZM,V050,20131231,EMIG
  2,Available,050410256649750,20061126T10:40:15,vs,,
  2,Used,20110809T14:21:04,,825044142,1765121002150049
  1,00010,5000,MZM,V050,20131231,EMIG
  2,Available, 050410256649751,20061126T10:40:15,vs,,

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

2. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

3. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

4. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

5. Shell Programming and Scripting

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 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... (9 Replies)
Discussion started by: bhaski2012
9 Replies

6. UNIX for Advanced & Expert Users

Move a block of lines to file if string found in the block.

I have a "main" file which has blocks of data for each user defined by tags BEGIN and END. BEGIN ID_NUM:24879 USER:abc123 HOW:47M CMD1:xyz1 CMD2:arp2 STATE:active PROCESS:id60 END BEGIN ID_NUM:24880 USER:def123 HOW:4M CMD1:xyz1 CMD2:xyz2 STATE:running PROCESS:id64 END (7 Replies)
Discussion started by: grep_me
7 Replies

7. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

8. UNIX for Dummies Questions & Answers

Output text from 1st paragraph in file w/ a specific string through last paragraph of file w/ string

Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string. Previously, I was outputting just each paragraph with that search string with: cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Discussion started by: carpenn
2 Replies

9. 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

10. Shell Programming and Scripting

appending string to text file based on search string

Hi, I need to append string "Hi" to the beginning of the lines containing some specific string. How can I achieve that? Please help. Malay (1 Reply)
Discussion started by: malaymaru
1 Replies
Login or Register to Ask a Question