removing a line from a file and then placing into another file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers removing a line from a file and then placing into another file
# 1  
Old 09-08-2007
removing a line from a file and then placing into another file

grep `whoami` $1 >> file

this lets me take out the username from a file and then i move it to a file but i need it to do one step at a time because i want the occurences to be numbered like

1)HOME=/home/joe.bloggs
2)LOGNAME=joe.bloggs


instead of just

HOME=/home/joe.bloggs
LOGNAME=joe.bloggs



anyone any ideas
# 2  
Old 09-09-2007
You can acheive this using awk

Code:
awk '{print NR,")",$0 <file-name>

Cheers,
K
kamitsin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing ^M from last line alone of a UNIX File

Hi All, I am copying a file from windows to UNIX. After that copying it have the ctrl+M character in the file at the line break. But the file contains the data that also have ctrl+M. I want to re move the ctrl+M at the end of the line alone. My file structure is XML and last line doesnt... (3 Replies)
Discussion started by: Agantrope
3 Replies

2. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

3. Shell Programming and Scripting

Placing Duplicate Lines per section into another file

Hello, I need help in putting duplicate lines within a section into another file. Here is what I'm struggling with: Using this file “data.txt”: ABC1 012345 header ABC2 7890-000 ABC3 012345 Header Table ABC4 ABC5 593.0000 587.4800 ABC5 593.5000 587.6580 <= dup need to remove ABC5... (4 Replies)
Discussion started by: petersf
4 Replies

4. Shell Programming and Scripting

Removing same line from a file

Hello , I got a text file like that with many same line main/a/antlr/ main/a/apache2/ main/a/app-install-data-ubuntu/ main/a/apparmor/ main/a/apport/ main/a/apport/ main/a/apport/ main/a/apport/ main/a/apr-util/ main/a/apr-util/ main/a/apt/ main/a/apt/ main/a/apturl/the output... (1 Reply)
Discussion started by: davidkhan
1 Replies

5. Solaris

Placing a config file

Hi all, I need to place a custom configuration file for a script/program that will likely be sitting in /usr/sbin, but I am unsure of exactly where to place it. In RHEL was told the config file should be in /etc/sysconfig, but no such directory exists in Solaris. Will my config file simply sit... (5 Replies)
Discussion started by: Rocket2DMn
5 Replies

6. Shell Programming and Scripting

Removing last character from each line of file

How can I remove the last character from each line of a file? This must be done without "funny" characters, as I want to transfer the code to/from Windows. Any ideas? (17 Replies)
Discussion started by: cjhancock
17 Replies

7. Shell Programming and Scripting

Removing last line from file

Hi, I searched the forums but could not find anything that was very useful. I am trying to remove the very last line from a file and display the rest of the file. Is there a way to use cut and tail together? Any other suggestions? Thanks (8 Replies)
Discussion started by: akeenabawa
8 Replies

8. Shell Programming and Scripting

Removing text from a line in a file

Hi All, I would like to know how to remove text from a line in a file. eg to The 4 sets of numbers are not static ie they change on each line in each different file so if anyone can help that would be great. Jeremy (10 Replies)
Discussion started by: outthere_3
10 Replies

9. Shell Programming and Scripting

Placing lines file in array

Hiya I am fairly new to UNIX and have been asked to write some scripts.... I am working in the korn shell. What I am trying to do is to go through a delimited file: Testingline1;test;test Testingline2;test;test and place the lines into an Array so: Array = Testingline1;test;test Array... (4 Replies)
Discussion started by: ThomasvdH
4 Replies

10. Shell Programming and Scripting

Removing a particular line from a text file

Hi, I have a file called inp.txt the contents of the file are as follows MANI123|23|41 MANI123|96|23 I want to reove the first line of this file. How can I do it. Thanks in advance (5 Replies)
Discussion started by: sendhilmani123
5 Replies
Login or Register to Ask a Question