to remove space in a txt file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers to remove space in a txt file
# 15  
Old 01-13-2009
i regret for my impoliteness,though i didnt want to hurt you.
plz help me ,this code is fetching the multiple timestamp,i want only the first one.
like this,
Code:
bash-2.05$ perl -ne 'print $1 if /:\sStarted at (.*)$/;' DPRPT600.log
+ perl -ne 'print $1 if /:\sStarted at (.*)$/;' DPRPT600.log
`date`"Sun Jan 11 01:06:00 EST 2009Sun Jan 11 01:06:00 EST 2009Sun Jan 11 01:06:03 EST 2009Sun Jan 11 01:06:06 EST 2009Sun Jan 11 01:06:24 EST 2009bash-2.05$

Thanks in advance.

Last edited by manit; 01-13-2009 at 10:09 AM..
# 16  
Old 01-13-2009
i also want to store the first timestamp in a variable.
tahnks
# 17  
Old 01-13-2009
Quote:
i regret for my impoliteness,though i didnt want to hurt you.
plz help me ,this code is fetching the multiple timestamp,i want only the first one.
like this,
Code:
bash-2.05$ perl -ne 'print $1 if /:\sStarted at (.*)$/;' DPRPT600.log
+ perl -ne 'print $1 if /:\sStarted at (.*)$/;' DPRPT600.log
`date`"Sun Jan 11 01:06:00 EST 2009Sun Jan 11 01:06:00 EST 2009Sun Jan 11 01:06:03 EST 2009Sun Jan 11 01:06:06 EST 2009Sun Jan 11 01:06:24 EST 2009bash-2.05$
Thanks in advance.
If that's the case then why not just pipe the output and use head -1?

Then just assign the result to a variable like X=`perl ....`

Smilie
# 18  
Old 01-13-2009
Code:
bash-2.05$ perl -ne 'print $1 if /:\sStarted at (.*)$/;' DPRPT600.log | head -1
+ perl -ne 'print $1 if /:\sStarted at (.*)$/;' DPRPT600.log
+ head -1
`date`"Sun Jan 11 01:06:00 EST 2009Sun Jan 11 01:06:00 EST 2009Sun Jan 11 01:06:03 EST 2009Sun Jan 11 01:06:06 EST 2009Sun Jan 11 01:06:24 EST 2009bash-2.05$

its not working still it is getting the multiple timestamps.
# 19  
Old 01-13-2009
  1. My bad, it should read
    Code:
    perl -ne 'print "$1\n" if /:\sStarted at (.*)$/;' DPRPT600.log

  2. As for getting the output into a variable:
    Code:
    VAR=`perl...`

I suggest reading up on the chapter "Expansion" in bashs manpage, especially the section titled "Command Substitution"
# 20  
Old 01-13-2009
thanks pludi.
the cut cammond is also working here.
Code:
bash-2.05$ start_timestamp=`perl -ne 'print $1 if /:\sStarted at (.*)$/;' DPRPT600.log | cut -c 8-26`
++ perl -ne 'print $1 if /:\sStarted at (.*)$/;' DPRPT600.log
++ cut -c 8-26
+ start_timestamp=Sun Jan 11 01:06:00
bash-2.05$ echo $start_timestamp
+ echo Sun Jan 11 01:06:00
Sun Jan 11 01:06:00
bash-2.05$

thanks to all of you to help me...
bye
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove space before numbers in delimited file

Hi, I have a file which looks like this FORD|1333-1| 10000100010203| 100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 I need the output to look like this FORD|1333-1|10000100010203|100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 The leading... (8 Replies)
Discussion started by: wahi80
8 Replies

2. Shell Programming and Scripting

How to remove space and delimit a csv file?

Hi All , I am facing a small challenge i need unix command to remove space as well as replace "|" to "," in a csv file . original file : A | B | c | D E | F | G | H I | J | K | L P | M | N | O Expected o/p: A,B,c,D E,F,G,H I,J,K,L P,M,N,O (4 Replies)
Discussion started by: Sweety532
4 Replies

3. Shell Programming and Scripting

How to remove space from each record in file?

Hi , I want to remove space from each record in one file My file is like BUD, BDL ABC, DDD, ABC ABC, DDD, DDD, KKK The o/p should be BUD,BDL ABC,DDD,ABC ABC,DDD,DDD,KKK Can any one help me regarding this? (9 Replies)
Discussion started by: jagdishrout
9 Replies

4. Shell Programming and Scripting

Remove space in whole file -perl

Hi all, I have a file which have say about 123,000 records, the records in it look like: 1294160401681,05-01-2011 00:00:01,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost, 1294160406515,05-01-2011 00:00:06,68,Cjw,2,0207,7,1100,900,SUCCESS,200,68,localhost, 1294160410097,05-01-2011... (3 Replies)
Discussion started by: danihamdani
3 Replies

5. Shell Programming and Scripting

Command to remove numbers from beginning of txt file

Hello. I have the following issue: my txt file has the following format: train/dr4/fklc0/sx175.txt 0 80282 Severe myopia contributed to Ron's inferiority complex. train/dr4/fklc0/sx355.txt 0 42906 Dolphins are intelligent marine mammals. train/dr4/fklc0/sa2.txt With the... (1 Reply)
Discussion started by: li_bi
1 Replies

6. Shell Programming and Scripting

Export data from DB2 table to .txt file(space delimited)

Hi I need help on this. Its very urgent for me.. please try to help me out.. I have data in tables in DB2 database. I would like to export the data from DB2 tables into a text file, which has to be space delimited. so that I can carry out awk, grep operations on that file. I tried to export... (2 Replies)
Discussion started by: ss3944
2 Replies

7. UNIX for Dummies Questions & Answers

Space in file how to remove

Hello I have a file with data something like this in it : texttexttext "text .lst" TEXT=" text " texttexttext "moretext .lst" TEXT=" text " Question is how do I get rid of space so that the files looks like this : texttexttext "text.lst" TEXT="text" texttexttext... (8 Replies)
Discussion started by: davebw
8 Replies

8. Shell Programming and Scripting

remove space from file content

i am a bit new to shell scripting i have a file containing xxxx xx xx but i want to output the content as xxxxxxxx. thus removing the space. any idea how i can do this (4 Replies)
Discussion started by: blackzinga
4 Replies

9. Shell Programming and Scripting

sed to remove last 2 characters of txt file

sed 's/^..//' file1.txt > file2.txt this will remove the first two characters of each line of a text file, what sed command will remove the last two characters? This is a similar post to my other....sry if I'm being lazy.... I need a file like this (same as last post) >cat file1.txt 10081551... (1 Reply)
Discussion started by: ajp7701
1 Replies

10. Shell Programming and Scripting

remove first column of a space delimited txt

how to remove the first column of a space delimited txt file? there are 12+ columns... what is the cleanest way? could use awk and print all but the first, but it looks kinda ugly awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "$10" "$11" "$12"}' file.txt whats a better way? (1 Reply)
Discussion started by: ajp7701
1 Replies
Login or Register to Ask a Question