script to move text in file?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to move text in file?
# 1  
Old 10-14-2007
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.

here is an example of what i am looking at

heres how the text file is now.
1960's: who recorded groovin?young rascals
1960's: who recorded like a rolling stone?bob dylan

needs to look like this
young rascals|1960's: who recorded groovin?
bob dylan|1960's: who recorded like a rolling stone?

if anyone can help me out with this please do.. it will take me forever to do it by hand

thanks in advance
# 2  
Old 10-14-2007
nvm someone on freenode told me how to do it

sed -i 's/\(.*?\)\(.*\)/\2|\1/'
# 3  
Old 10-15-2007

This one is also ok.

awk 'BEGIN{FS="?"}
print $2"|"$1"?"
}' a

# 4  
Old 10-16-2007
Here's another

# Move text in a file ($1)
while read LINE
  FIELD1=$(echo ${LINE} | cut -d"?" -f1)
  FIELD2=$(echo ${LINE} | cut -d"?" -f2)
  echo "${FIELD2}|${FIELD1}?"
done < $1

Just to be different...

Slower, I'm sure. I just want to see if I could do it without sed or awk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with file compare and move script

I'm running debian (the raspbian version of it) and working on a script to compare files in 2 directories, source and target, move files with duplicate names to a 3rd directory, then move remaining files in source to target. I can't get the syntax right, keep getting syntax errors and can't get... (7 Replies)
Discussion started by: mattz40
7 Replies

2. UNIX for Dummies Questions & Answers

Grep : Filter/Move All The Lines Containing Not More Than One "X" Character Into A Text File

Hi All It's me again with another huge txt files. :confused: What I have: - I have 33 huge txt files in a folder. - I have thousands of line in this txt file which contain many the letter "x" in them. - Some of them have more than one "x" character in the line. What I want to achieve:... (8 Replies)
Discussion started by: Nexeu
8 Replies

3. Shell Programming and Scripting

Move file in to directory- script

Hi In directory /mnt/upload I have about 100 000 files (*.png) that have been created during the last six months. Now I need to move them to right folders. eg: file created on 2014-10-10 move to directory /mnt/upload/20141010 file created on 2014-11-11 move to directory /mnt/upload/20141111... (6 Replies)
Discussion started by: primo102
6 Replies

4. Shell Programming and Scripting

Script to move file on a daily basis

Hi! Please I need help on the a script that would pick one file in a directory, change its name, them change its permissions, them move to a different directory, but has to be done on a daily basis, and the file that is being moved to its final destination has to have the following format:... (7 Replies)
Discussion started by: fretagi
7 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. Shell Programming and Scripting

Shell script to get the latest file from the file list and move

Hi, Anybody help me to write a Shell Script Get the latest file from the file list based on created and then move to the target directory. Tried with the following script: got error. A=$(ls -1dt $(find "cveit/local_ftp/reflash-parts" -type f -daystart -mtime -$dateoffset) | head... (2 Replies)
Discussion started by: saravan_an
2 Replies

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

8. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

9. Shell Programming and Scripting

script to move two lines to the end of a file

My input file is multiline file and I am writing a script to search for a pattern and move the line with the pattern and the next line to the end of the file. Since I am trying to learn awk, I thought I would try it. My input looks like the following: D #testpoint 1 510.0 D #testpoint2 ... (5 Replies)
Discussion started by: banjo25
5 Replies

10. 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
Login or Register to Ask a Question