Sponsored Content
Top Forums Shell Programming and Scripting Remove space in whole file -perl Post 302485674 by danihamdani on Wednesday 5th of January 2011 11:45:29 PM
Old 01-06-2011
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 00:00:10,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,
1294160413815,05-01-2011 00:00:13,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,
1294160417389,05-01-2011 00:00:17,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,

1294160421087,05-01-2011 00:00:21,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,
1294160425975,05-01-2011 00:00:25,68,Cjw,2,0208,7,1100,900,SUCCESS,200,68,localhost,
1294160430483,05-01-2011 00:00:30,68,Cjw,2,0207,7,1100,900,SUCCESS,200,68,localhost,

1294160435542,05-01-2011 00:00:35,68,Cjw,2,0207,7,1100,900,SUCCESS,200,68,localhost,
1294160439128,05-01-2011 00:00:39,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,

...
This is how it looks, if u notice there is a space or carriage return between some records and im planning to remove that. So the the records that i want 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 00:00:10,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,
1294160413815,05-01-2011 00:00:13,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,
1294160417389,05-01-2011 00:00:17,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,
1294160421087,05-01-2011 00:00:21,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,
1294160425975,05-01-2011 00:00:25,68,Cjw,2,0208,7,1100,900,SUCCESS,200,68,localhost,
1294160430483,05-01-2011 00:00:30,68,Cjw,2,0207,7,1100,900,SUCCESS,200,68,localhost,
1294160435542,05-01-2011 00:00:35,68,Cjw,2,0207,7,1100,900,SUCCESS,200,68,localhost,
1294160439128,05-01-2011 00:00:39,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost,

...
Here is the code which i have written.. but someone should help me in completing it... thanks in advance

open(file_tmp,"<","$chk_file");
while (my $line = <file_tmp>)
{
$line =~ s/\n//g;
open(out,">>",tmpfile);
print out $line;
close(out);
}
close(file_tmp);

Please correct me if im wrong.. thank you.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

to remove space in a txt file

I want to fetch text after the first occurance of the word "started at" i.e. consider a text written below... echo 'hi how r u ' Started at MON Jan 11 00:03:24 EST 2009 echo 'hi how is ur job goin on' Started at Sun Jan 11 00:03:24 EST 2004 Started at TUE Jan 11 00:03:24 EST 2005 Started... (19 Replies)
Discussion started by: manit
19 Replies

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

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

4. Shell Programming and Scripting

perl: conditionaly remove space

I want to remove all space NOT starting with http, the following works, but not elegant, is there better way? $echo " a http b" | perl -lne 's/\shttp/#http/g; s/\s+//g; s/#http/ http/g; print $_;' a httpb (4 Replies)
Discussion started by: honglus
4 Replies

5. Shell Programming and Scripting

How to remove tab space and new line from a file using sed?

i am using the default sed package that comes with solaris. (11 Replies)
Discussion started by: chidori
11 Replies

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

7. Shell Programming and Scripting

[Solved] Howto remove extra space in the file

Hi Gurus, I have a file which contains some special char or space. when using cat -evt I can see the file as following: 0,"0000","abc/def aaa ... (6 Replies)
Discussion started by: ken6503
6 Replies

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

9. Shell Programming and Scripting

Remove trailing space from file and folder names

I have a folder that contains many sub folders and files. This tree has to be backed up to an archive system. According to the tech support, one of the archives is failing to back up due to the possibility of trailing spaces on file and folder names. Therefore, I would like to have a script... (16 Replies)
Discussion started by: vipertech
16 Replies

10. 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
arpsend(8)							    Containers								arpsend(8)

NAME
arpsend - send ARP requests SYNOPSIS
arpsend -D -e target_ip [ -e target_ip ...] [-c count] [-w timeout] interface arpsend -U -i source_ip [-c count] [-w timeout] interface DESCRIPTION
Utility arpsend sends ARP packets on device interface to detect or update neighbours' ARP caches with a given IP. COMMANDS
Run utility with one of the following commands: -D Send broadcast ARP request to detect neighbours with target_ip. You have to specify target_ip (-e option). -U Send broadcast ARP request to update neighbours' ARP caches with source_ip. You have to specify source_ip (-i option). OPTIONS
-c count Number of packets to send. Default is infinity. -w interval Interval between packets, in seconds. Default is 1 second. -i source_ip_address Set source IP address field in ARP packet. -e target_ip_address Set target IP address field in ARP packet. Note that you can specify -e option multiple times to detect many IP addresses in one utility call. EXIT STATUS
arpsend returns 0 upon successful execution. If something goes wrong, it returns an appropriate error code. 1 EXC_USAGE Usage error 2 EXC_SYSTEM System error 3 EXC_RECV ARP reply was received EXAMPLES
To send request on interface eth0 to detect any neighbour computers with IP 192.168.10.200: arpsend -D -e 192.168.10.200 eth0 To send request on interface eth0 to update neighbours' ARP caches with IP 192.168.10.200: arpsend -U -i 192.168.10.200 eth0 NOTES
Interface you use have to be arpable and not be loopback (i.e. /sbin/ip link show interface should show neither NOARP nor LOOPBACK flags in interface parameters). SEE ALSO
vzctl(8). LICENSE
Copyright (C) 2000-2011, Parallels, Inc. Licensed under GNU GPL. OpenVZ 28 Jun 2011 arpsend(8)
All times are GMT -4. The time now is 05:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy