Trim Space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trim Space
# 1  
Old 11-24-2015
Trim Space

In Shell, I have output of a unix command as

Code:
test1 
test2015

but I want it as
Code:
test1 test2015

can anyone help me out.

Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 11-24-2015 at 03:29 AM..
# 2  
Old 11-24-2015
Hello OscarS,

Welcome to forums, please use code tags as per forum rules to codes/Inputs/commands used in your posts as per forum rules. Now coming on to your request, you haven't mentioned which command you have used to get the shown output, you could following and let me know if that helps.
Code:
Your_command | awk '{A=A?A OFS $0:$0} END{print A}'

In case you need to get input from a file then you could use as follows.
Code:
awk '{A=A?A OFS $0:$0} END{print A}'  Input_file

As always on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk , or nawk.

Thanks,
R. Singh
# 3  
Old 11-24-2015
Or, more simply:
Code:
your_command | tr '\n' ' ';echo

# 4  
Old 11-24-2015
Or
Code:
echo $(your_command)

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trim String

Hi, I wish to grep everything before the last "/bin" in the following string /opt/app/bin/app1/jdk150_07/bin/IA64N/java Desired output: "/opt/app/bin/app1/jdk150_07" Kindly help ... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

awk - trim white space from a field / variable

Hi, Consider the data (FS = |): 1| England |end 2| New Zealand |end 3|Australia|end 4| Some Made Up Country |end 5| West Indies|end I want the output to be (i.e. without the leading and trailing white space from $2) England New Zealand Australia Some Made Up Country West... (4 Replies)
Discussion started by: Storms
4 Replies

3. Shell Programming and Scripting

Trim a new line

Okay, I am trying to make a bash script to get a certain domains IP address (my home ip). My home is on a DHCP lease from my ISP, so I cannot always trust the IP address to remain constant. This is what I have so far for it: alias ip-home="ping -c 1 example.com | grep 'PING' | cut -d'(' -f2 |... (5 Replies)
Discussion started by: tnanek
5 Replies

4. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

5. Programming

How to trim the white space around a string in C program

I am coding a C program to read a plain text file. There are a lot of blank fields or a string with white spaces. I want to know is there such a function called trim() in C to clean the white space around a string? Or some other way can do this efficiently? Thanks. (18 Replies)
Discussion started by: hxm1303
18 Replies

6. Shell Programming and Scripting

Trim issue

Hi All, I am using trim in my code.. ID_SA_SOURCE="`echo "$data" | cut -c17-34 | tr -s " "`" ID_SA_DEST="`echo "$data" | cut -c35-52 | tr -s " "`" echo"$ID_SA_SOURCE";"$ID_SA_DEST"; the output is 0608166896; 3001339; contains one whitespace between the two ..how can i remove that single... (3 Replies)
Discussion started by: scorpio
3 Replies

7. Shell Programming and Scripting

trim lines

I want to delete all lines from 1 till a certain line. how to do that without redirection to another file (tail solution)? thanx (6 Replies)
Discussion started by: melanie_pfefer
6 Replies

8. Shell Programming and Scripting

Trim

Hello, I am passing a filename to a script to draw parameters from it. However, I want to use part of the filename as a parameter. The filename is transfer_ccf_3731_10.sh but I only need the 3731_10 part of it. Is this possible? Any help or suggestions would be appreciated! Regards, J. (4 Replies)
Discussion started by: JWilliams
4 Replies

9. Shell Programming and Scripting

trim whitespace?

I'm trying to find a command that will trim the white space off a string. e.g. $str = " stuf " $str = trim ( $str ) echo $str // ouput would just be stuf Thanks, Mark (4 Replies)
Discussion started by: msteudel
4 Replies

10. Shell Programming and Scripting

How to trim space in output variable ?

Hi , I have a code like this: uid=scott password=tiger database=db01 cat >runid_val.sql<<-EOA SET ECHO OFF SET FEEDBACK OFF SET HEADING OFF SELECT trim(runid_seq.nextval) FROM dual; EXIT EOA echo `cat runid_val.sql` V_RUNID=`sqlplus -s $uid/$password@$database @runid_val.sql`... (5 Replies)
Discussion started by: vj_76
5 Replies
Login or Register to Ask a Question