Replacing the last data of each line ina file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing the last data of each line ina file
# 1  
Old 02-01-2008
CPU & Memory Replacing the last data of each line ina file

Hi,

I ahve a file where the format is as given below:

qqq dfsf gdfjkg gjdosjg jkflsjd 21
fdksdlf fsdnkfl lkdfsgjld 45
laefsdl fsdlfksl fsdklflk gfsdl 56

I need to replace the last number by space or delete the last number in each line. (by using awk/sed/grep)

Can U please help me with this .

thanks in advance
Js
# 2  
Old 02-01-2008
MySQL

Dear jisha,

u can try this

sed 's/[0-9]*$//' filename

Regards,
Pankaj
# 3  
Old 02-01-2008
Thank you so much Pankaj
Its working
Js
# 4  
Old 07-30-2008
hi
i m not geeting any command for writing data in any existing file at end
of file though linux commands.plz suggest me anything for it.

kranti
Smilie
# 5  
Old 07-30-2008
Quote:
Originally Posted by kranti hande
hi
i m not geeting any command for writing data in any existing file at end
of file though linux commands.plz suggest me anything for it.

kranti
Smilie
Parser failed; syntax error at line 1.
# 6  
Old 08-04-2008
Code:
awk '{for(i=1;i<=NF-1;i++){printf("%s ",$i)};print "";}' filename

# 7  
Old 08-04-2008
hello kranti,
You can just append command output to the file like,

Code:
command >> filename

- nilesh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing Data in a File

Hi All, Have a requirement where i needs to alter the Content of File once it is generated. The File consist of Multiple line ...range from 2000-8000 lines. I need to change the Content of Lines which match this Pattern ... (14 Replies)
Discussion started by: asheshrocky
14 Replies

2. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

3. Shell Programming and Scripting

Replacing a line in a file

Hi all, I need to replace a line export TZ=xxxxxxxx with the line export TZ=$1 Now, "xxxxxxxx" in the above line is some unknown string and $1 is a parameter. I want the content of $1 to be replaced with "xxxxxxxx". Kindly help me how to do this in the shell scripting. (5 Replies)
Discussion started by: ddeeps2610
5 Replies

4. Shell Programming and Scripting

Replacing data in one file with data in another

Hello, I have 2 files delimited by "|". File1: 1|New York 12| Buffalo 599| Syracuse File2: 56 Kennedy |1 9 Burridge Pl|15 98 BELL ROCK |599 My goal: Is to replace the numerical numbers in "File 2" (second field, not street address) with the corresponding city names from... (2 Replies)
Discussion started by: vestport
2 Replies

5. Shell Programming and Scripting

Replacing line 'i' of file1 with line 'j' of file 2

Hi All, As mentioned in the title I have two text files and I would like to replace line number 5 of file #1 with line number 4 of file #2 e.g. file 1 wqwert 4.4464002 3 319 286 369 46.320002 56.150002 45.100002 1 1 1 0.723 (12 Replies)
Discussion started by: f_o_555
12 Replies

6. Shell Programming and Scripting

Replacing the last character for each line in a file

Hello, I have a csv file and will like to replace the last character of each line in the file with Z (20 Replies)
Discussion started by: 123script
20 Replies

7. Shell Programming and Scripting

Replacing data of output file with input

Hi, I have a ksh which peocess and get me data from 3 days... ie if i process it on jan 28.. it gets data for 25, 26 and 27.... the process run every day and get previous 3 days data...all this data is appened to a file lets call time.out Now time.out cannot have deplicate data so what i want... (10 Replies)
Discussion started by: bhagya2340
10 Replies

8. Shell Programming and Scripting

Replacing a line in a file - HELP!!!

I have a problem in the following code ... while read line do #Get Line Number OLDLINE=`sed -n $Lineno $filename` echo "Un Changed Line : "$OLDLINE echo "Enter a New Pattern : " read NewPattern <&1 echo "NewPattern :"$NewPattern NEWLINE=`cat $filename | sed -n... (1 Reply)
Discussion started by: maxmave
1 Replies

9. Shell Programming and Scripting

Retreive content between specific lines ina file

Hi I have a text file which has two sets of lines repeating for "n" number of times.Some data is printed between the two lines.I want to retrieve all the data thats there in between those two set of lines.I have the string value of those two set of lines. To be much more clearer ... (4 Replies)
Discussion started by: chennaitomcruis
4 Replies

10. UNIX for Advanced & Expert Users

how to put quotes ina .sql file

Hi i am new on Unix.......... I have to write a ddl and for tables and I am using single quotes in the comment for the table and its column...........but when i see on the unix server the ' dont show . e.g. DROP TABLE DMR_PURGED; CREATE TABLE DMR_PURGED ( HEALTH_SERVICE_ID ... (9 Replies)
Discussion started by: agarwalniru
9 Replies
Login or Register to Ask a Question