Moving a line to the end of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving a line to the end of the file
# 1  
Old 10-12-2011
Moving a line to the end of the file

I have a file with different directories in it. I would need to move one line within the file to the end of the list. Also not there could be blank line in the middle of it. Example

Code:
/vol/fs1

/vol/fs2 

/vol/fs3
/vol/fs4
/vol/fs5
/vol/fs6

/vol/fs7

So I would need /vol/fs2 after /vol/fs7 like so

Code:
/vol/fs1

/vol/fs3
/vol/fs4
/vol/fs5
/vol/fs6

/vol/fs7

/vol/fs2

Thanks
# 2  
Old 10-12-2011
What criteria made you choose "/vol/fs2" to be moved to the end of the file?
# 3  
Old 10-12-2011
Code:
awk 'END {print t} /fs2/{t=$0;next}1' infile

# 4  
Old 10-14-2011
Thanks rdcwayx...It works, how would I add a blank like above it once it is moved tot the bottom of the list.

Thanks in advance
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

3. Shell Programming and Scripting

From line 2 to end file

Hello all, I have filex $cat filex camp1 camp2 camp3 111 222 333 444 555 666 777 888 999 then i need output with and not line 1 or line 2 to end file $cat filex 111 222 333 444 555 666 777 888 999 thank you, (3 Replies)
Discussion started by: aav1307
3 Replies

4. Shell Programming and Scripting

Sed: how to merge two lines moving matched pattern to end of previous line

hello everyone, im new here, and also programming with awk, sed and grep commands on linux. In my text i have many lines with this config: 1 1 4 3 1 1 2 5 2 2 1 1 1 3 1 2 1 3 1 1 1 2 2 2 5 2 4 1 3 2 1 1 4 1 2 1 1 1 3 2 1 1 5 4 1 3 1 1... (3 Replies)
Discussion started by: satir
3 Replies

5. UNIX for Dummies Questions & Answers

Moving lines of file to command line

I have a file in which each line is the name of another file. Is there a way to serve them to the command line? For example, if the file contains file1.txt file2.txt file3.txt ... file9.txt is there a way to insert them in the command as a batch? If I ran a command like grep... (4 Replies)
Discussion started by: wbport
4 Replies

6. Shell Programming and Scripting

Adding tab/new line at the end of each line of a file

Hello Everyone, I need a help from experts of this community regarding one of the issue that I am facing with shell scripting. My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line. The... (20 Replies)
Discussion started by: Sourav Das
20 Replies

7. Shell Programming and Scripting

Add name at the end of line in one file

Hi Folks, I want to add one name at the end of one file. Below line i have to add end of line some name... Search_masterlogin=`grep -i $masterlogin passwd.master|awk -F: '{print $1}'` $ grep -i susan passwd.master |awk -F: '{print $1}' susan $ I want to insert one name called... (10 Replies)
Discussion started by: susindram
10 Replies

8. Shell Programming and Scripting

Help with shell script: moving end of line character

Hello. I have a file (old.txt) that I need to copy into another file (new.txt). Each line on old.txt ends with CR/LF but the position of CR/LF varies from one record to another. I need to copy each line of record to new.txt and move CR/LF in pos 165. Can I use awk to achieve this? How?... (8 Replies)
Discussion started by: udelalv
8 Replies

9. UNIX for Dummies Questions & Answers

moving char to end

I need to move the 5th char of a word to its end and first four chars and rest should be retained as it is. Can any one help me out... (1 Reply)
Discussion started by: Ramkum
1 Replies

10. Shell Programming and Scripting

Append a field to the end of each line of a file based on searching another file.

Hi All, I have two comma separated value(CSV) files, say FileA and FileB. The contents looks like that shown below. FileA EmpNo,Name,Age,Sex, 1000,ABC,23,M, 1001,DES,24,F, ... (2 Replies)
Discussion started by: ultimate
2 Replies
Login or Register to Ask a Question