Remove multiple blanks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove multiple blanks
# 1  
Old 04-11-2012
Remove multiple blanks

Hi,

I have data as below
Quote:



203.188.200.1


tp2.yahoo.com

Y
3.1
3.1
0
Neutral
And I want output as

Quote:
203.188.200.1 tp2.yahoo.com Y 3.1 3.1 0
Thanks

Last edited by Anjan1; 04-11-2012 at 11:45 AM.. Reason: Added more info
# 2  
Old 04-11-2012
Code:
 
awk '$1=$1' ORS=" " input_file

# 3  
Old 04-11-2012
Quote:
203.188.200.1


tp2.yahoo.com

Y
3.1
3.1
0
Neutral

203.188.200.12


tp1.yahoo.com

Y
3.1
3.1
0
Neutral

203.188.200.13


tp3.yahoo.com

Y
3.1
3.1
0
Neutral
I want output like this:

Quote:
203.188.200.1 tp2.yahoo.com Y 3.1 3.1 0 Neutral
203.188.200.12 tp1.yahoo.com Y 3.1 3.1 0 Neutral
203.188.200.13 tp3.yahoo.com Y 3.1 3.1 0 Neutral
The above command including all in one line

Last edited by Anjan1; 04-11-2012 at 12:26 PM.. Reason: adding info
# 4  
Old 04-11-2012
Code:
 
awk '/[0-9.]{4}/ && NR ==1 {a=$0;next} /[0-9.]{4}/ { print a;a=$0;next} {a=a" "$0} END{ print a}' input_file


Last edited by panyam; 04-11-2012 at 12:44 PM.. Reason: replace [0-9] {4}
# 5  
Old 04-11-2012
I didn't got the output i requested.
# 6  
Old 04-12-2012
Code:
xargs -n 7 < infile

or
gnu sed
Code:
sed '/^$/d' infile | sed -n 'h;n;H;n;H;n;H;n;H;n;H;n;H;x;s/\n/ /g;p'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove row 1 and blanks

I am trying to remove $1 along with the blank values from the file. Thank you :). file R_Index Chr Start End Ref Alt Func.IDP.refGene Gene.IDP.refGene GeneDetail.IDP.refGene Inheritence ExonicFunc.IDP.refGene AAChange.IDP.refGene avsnp147 PopFreqMax ... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Advanced & Expert Users

To Remove multiple new lines

Hi , I have file which consists of multiple new lines. I need to identify the new line in every row of the file and remove it. It is having record delimiter as "|" and final delimiter of the line is "end" Can anyone from the forum suggest me how to remove the news lines from entire file? example... (11 Replies)
Discussion started by: etldeveloper
11 Replies

3. Shell Programming and Scripting

Leading blanks

Hi Ich have a list as follows 73 5 100 45 81 4 and I would like to have an output (on screen) like that 73 5 100 45 81 4 (6 Replies)
Discussion started by: lazybaer
6 Replies

4. Shell Programming and Scripting

regex to remove commentaries and blanks

Hi all, I need to prune a var's content as follows: VAR='blah blah # seew seew' NEWVAR='blah blah' (without blanks) I need also to perform this change by using variable substitution within bash shell. I've tried it with the following subst: VAR2=${VAR/ \#*/} but the... (7 Replies)
Discussion started by: yomaya
7 Replies

5. Shell Programming and Scripting

Replace multiple blanks within double quotes

I have various column names within double quotes, separated by commas. Example: "column one", "column number two", "this is column number three", anothercolumn, yetanothercolumn I need to eliminate the double quotes and replace the blanks within the double quotes by underscores, giving: ... (5 Replies)
Discussion started by: jgrogan
5 Replies

6. Shell Programming and Scripting

how to remove trailing blanks, tabs

Hi I need to delete trailing spaces, tabs and unprintable charactes from the file. This file has a number of blank lines which should be left intact. Another words I am trying to remove the junk at the end of each line. Does anyone come across the similar problem? Thanks a lot for any help -A (3 Replies)
Discussion started by: aoussenko
3 Replies

7. Programming

Blanks vs: Nulls

I'm relatively new to Pro*C programming. In the following example: char name; EXEC SQL SELECT 'John Doe' INTO :name FROM DUAL; "John Doe" is in positions 0-7, blanks in 8-19, and a null in 20. I would really prefer the null to be in position 8 and I don't care what's after that. I wrote a... (1 Reply)
Discussion started by: ebock
1 Replies

8. UNIX for Advanced & Expert Users

numbering blanks

hello i'm trying to figure out how to number a blank line. For instance this : sed '/./=' file | sed '/./N; s/\n/ /' gives me 1 aaaa 2 bbbbbb 4 cccccc 5 ffkkkfff 6 ffsdfdfs I would like something like this: 1 aaaaa 2 3 bbbbbb 4 5 cccccc And so... (6 Replies)
Discussion started by: wisher115
6 Replies

9. Shell Programming and Scripting

blanks in file name

I have a file with a list of filenames. I want to work loopwise through the file and operate on each of the listed files. Normally I'd do something like: for file in `cat $mydir/file-list` do echo $file >> $mydir/my.log cp $mydir/$file $newdir done the problem is that my... (1 Reply)
Discussion started by: LisaS
1 Replies

10. Shell Programming and Scripting

remove multiple characters once

i have a variable in a bash shell script called $hostname. $hostname will always be different except it will always start with "-s " that is a - an s and a space. so echo $hostname will look like this: -s somehostname.com how can i get rid of the leading -s ? ive tried tr -d but that gets... (2 Replies)
Discussion started by: norsk hedensk
2 Replies
Login or Register to Ask a Question