Sponsored Content
Full Discussion: Remove space with sed
Top Forums UNIX for Beginners Questions & Answers Remove space with sed Post 303037247 by arm on Saturday 27th of July 2019 07:25:58 AM
Old 07-27-2019
Remove space with sed

Hello Folks ,
myfile contains 1000000 records as follows:
Code:

logver=56 idseq=63256 itime=1111 devid=TG-40 devname=PUI-C2 vd=USER date=2019_01_10 time=18:39:49 logid="000013" type="traffic" subtype="forward" level="notice" eventtime=134 srcip=1.1.1.1 srcport=1 srcintf="XYX-CORE.01" srcintfrole="undefined" dstip=2.2.2.2 dstport=17 dstintf="W-XY.100" dstintfrole="undefined" poluuid="e7a88496-b510-51e7-dbcd-384d6bbc0805" sessionid=24343 proto=17 action="accept" policyid=1 policytype="policy" service="udp/17000" dstcountry="United States" srccountry="Reserved" trandisp="snat" transip=120.1.1.1 transport=23136 duration=90 sentbyte=33 rcvdbyte=36 sentpkt=1 rcvdpkt=1 appcat="unscanned"

cat myfile | sed 's/[a-z] *  //g' | awk '{for(i=1;i<=NF;i++){if($i~/dstcountry/) printf "|%s",$i};printf "\n" }' | \
sed 's/^|//g;s/[a-z]*.=//g;s/"//g'

after run above script I got
Code:
UniteStates

I need it to be
Code:
UnitedStates

I think the problem with first "sed" of mine , need to know how to remove the space between two words in double quote "String1 space String2"

Last edited by Neo; 07-27-2019 at 08:59 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to remove space after numeric

I have a script that shows me the disk SPace used by different dir under my home dir: #!/bin/ksh cd /ednpdtu3/u01/pipe p1=`df -g | tail -1 | tr -s " " | cut -d " " -f2` echo "Total Disk Space of Home Dir is $p1 GB" p2=`df -g | tail -1 | tr -s " " | cut -d " " -f3` echo "Total Disk Space... (2 Replies)
Discussion started by: ali560045
2 Replies

2. Shell Programming and Scripting

How to remove space in sed for / character

Hi... i need a script to remove the space before and after the operator like( / ). Ex : Input file apple / manago mango / fresh apple / fresh Desired output: apple/manago mango/fresh apple/fresh Note: betwee the desired operator space should be removed, between words do not remove... (3 Replies)
Discussion started by: vasanth_vadalur
3 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

Remove space

DATE=6/Jul/2010 6/Jul/2010 var="sed -n '/\ ---------- Post updated at 11:49 AM ---------- Previous update was at 11:36 AM ---------- #!/bin/bash DATE=`./get_date.pl 3` DATE1=`./get_date.pl 2` var1=$( echo "$DATE" | sed "s/ //g" ) var2=$( echo "$DATE1" | sed "s/ //g" ) var="sed -n... (1 Reply)
Discussion started by: sandy1028
1 Replies

5. Shell Programming and Scripting

Remove space before a character

Hi guys, I am new to shell scripting and I have a small problem...If someone can solve this..that would be great I am trying to form a XML by reading a flat file using shell scripting This is my shell script LINE_FILE1=`cat FLEX_FILE1.TXT | head -1 | tail -1` echo... (1 Reply)
Discussion started by: gowrishankar05
1 Replies

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

7. Shell Programming and Scripting

remove space

File A.txt A005 -119.5 -119.5 -100.5 A006 -120.5 -119.5 -119.3 A008 0 0 0 Output A005 -119.5 -119.5 -100.5 A006 -120.5 ... (1 Reply)
Discussion started by: asavaliya
1 Replies

8. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

9. Shell Programming and Scripting

sed - remove space and . for a pattern

Hi, I have file which contains following lines A| 965.|Mr.|35.45| 66. B| 33.| a456.| 77. The output should be A|965|Mr.|35.45|66 B|33| a456.|77 Basically if a Number has space in prefix and . in suffix remove both. So pattern could be if there is a | which has next two characters as... (1 Reply)
Discussion started by: wahi80
1 Replies

10. Shell Programming and Scripting

Remove space from numeric value

Hello, I need help. I have xml file and there are one extra space on number <EpiReference>1 42345</EpiReference>. And of cource, the value change on every new file. I need remove space from that value what is in between <EpiReference> and </EpiReference>. How I can do that? This are example... (9 Replies)
Discussion started by: Jopsulainen
9 Replies
Perl::Critic::Policy::RegularExpressions::RequireLineBouUseryContributedPerl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching(3pm)

NAME
Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching - Always use the "/m" modifier with regular expressions. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Folks coming from a "sed" or "awk" background tend to assume that '$' and '^' match the beginning and end of the line, rather than then beginning and end of the string. Adding the '/m' flag to your regex makes it behave as most people expect it should. my $match = m{ ^ $pattern $ }x; #not ok my $match = m{ ^ $pattern $ }xm; #ok CONFIGURATION
This Policy is not configurable except for the standard options. NOTES
For common regular expressions like e-mail addresses, phone numbers, dates, etc., have a look at the Regexp::Common module. Also, be cautions about slapping modifier flags onto existing regular expressions, as they can drastically alter their meaning. See <http://www.perlmonks.org/?node_id=484238> for an interesting discussion on the effects of blindly modifying regular expression flags. AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching(3pm)
All times are GMT -4. The time now is 06:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy