The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
insert text into column knoxo Shell Programming and Scripting 1 03-31-2008 05:01 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
insert a variable in the last column of a file dineshr85 Shell Programming and Scripting 7 12-06-2007 07:46 AM
(sed) parsing insert statement column that crosses multiple lines jjordan Shell Programming and Scripting 3 10-09-2007 12:23 AM
Replace 10th column with a new column--- Terriblly hurry ahmedwaseem2000 Shell Programming and Scripting 2 09-06-2005 01:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-20-2007
sslr sslr is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
How to insert tab at specified column.HELP

I have input like:
1234567890

cut -c1-3,6-7,9-10 input > output

Now I got 1236790.

I want to insert space between each cut. So the output like:
123 67 90

Can anybody help?
Thanks.
  #2 (permalink)  
Old 09-20-2007
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,759
One way to add spaces (not a tab or "\t" character):
Code:
awk '{print substr($0,1,3), substr($0,6,2), substr($0, 9,2)  }' > output
  #3 (permalink)  
Old 09-20-2007
sslr sslr is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
Is there other way using other UNIX command? awk is not working for me.
giving me "16 bit MS-DOS Subsystem" error message.
  #4 (permalink)  
Old 09-20-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 711
Hi.

Quote:
Originally Posted by sslr
I want to insert space between each cut. So the output like:
123 67 90
This is one alternative using GNU cut:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate insertion of string for cut output fields.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions of codes used in this script -- local code \"version\")"
version bash cut

echo
echo " Expecting |123 67 90|"

echo "1234567890" |
cut -c1-3,6-7,9-10 --output-delimiter=" "

exit 0
Producing:
Code:
% ./s1

(Versions of codes used in this script -- local code "version")
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
cut (coreutils) 5.2.1

 Expecting |123 67 90|
123 67 90
See man pages for details ... cheers, drl

Last edited by drl; 09-20-2007 at 05:06 PM..
  #5 (permalink)  
Old 09-21-2007
sslr sslr is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9

Thank you drl. You are so helpful.
  #6 (permalink)  
Old 09-21-2007
sslr sslr is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
What if two field being cut are next to each other, the delimiter will not be inserted?
cut -c1-3,4-5 --output-delimiter="|" input > output
The output will be:
12345

How to get 123|45?

Another question is how to get rid of the leading space, if I have input like:
1234567890
I'd like to have output
123|45
instead of
123|45

Could you please help?
Thanks.
Closed Thread

Bookmarks

Tags
linux, linux commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0