If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > multiple cuts in a line

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-04, 11:18
amolbc amolbc is offline
Registered User
 
Join Date: Mar 2004
Posts: 7
Question multiple cuts in a line

Hi,

a new pal in this great group...Hello everyone!

so what i need is to be able to cut a line vertically at different columns of course using the 'cut' command.
say like there is a line in a file a.txt which reads
"I am a boy."(excluding the " marks)

so i want to have in my output
I boy

what i thot of is
cat a.txt | cut -c1-1 -c8-10

but this when tried does not take all the -c's but only the last. so in this case i get boy and the first -c parameter goes unheeded..

any other way of using this cut or any other utility to have what i want?

bye
Reply With Quote
  #2 (permalink)  
Old 03-23-04, 11:51
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
You must specify only one -c option.
With this option you can specify a list of ranges separated by commas.

Code:
cut -c1-1,8-10 a.txt
Don't use 'cat' when you can specify the input file for the command.
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 03-24-04, 10:43
amolbc amolbc is offline
Registered User
 
Join Date: Mar 2004
Posts: 7
Quote:
Originally posted by aigles
You must specify only one -c option.
With this option you can specify a list of ranges separated by commas.

Code:
cut -c1-1,8-10 a.txt
Don't use 'cat' when you can specify the input file for the command.

hi,

thanks for the help...but later i found me helpless again..
so what i want now is to be able to place the columns wherever i want
so if i wanna concat 38-41 columns with 25 column and make it a single number say i am not able to do it....what it does is go from 1st column to the last and output the columns serially if asked for in the command....
so in this case i will get the number i want as

[25][38-41] and not as [38-41][25] which is what i want...

and again i also cannot delimit the columns in the output..like say
cut -c4-7," "1-2 a.txt

to get separate columns in the output

Last edited by amolbc; 03-24-04 at 10:45.
Reply With Quote
  #4 (permalink)  
Old 03-24-04, 12:10
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
You can do it with 'awk'

Code:
awk ' {
   print substr($0,38,4) substr($0,25,1) # print [25][38-41]
   print substr($0,4,4),substr($0,1,2)   # print [4-7] [1-2]
} ' a.txt

$0
The record read from file

substr(STRING, START [, LENGTH])

This returns a LENGTH-character-long substring of STRING, starting
at character number START. The first character of a string is
character number one. For example, `substr("washington", 5, 3)'
returns `"ing"'.

If LENGTH is not present, this function returns the whole suffix of
STRING that begins at character number START. For example,
`substr("washington", 5)' returns `"ington"'. The whole suffix is
also returned if LENGTH is greater than the number of characters
character number one. For example, `substr("washington", 5, 3)'
returns `"ing"'.

If LENGTH is not present, this function returns the whole suffix of
STRING that begins at character number START. For example,
`substr("washington", 5)' returns `"ington"'. The whole suffix is
also returned if LENGTH is greater than the number of characters
remaining in the string, counting from character number START.

print statement

The `print' statement does output with simple, standardized
formatting. You specify only the strings or numbers to be printed, in a
list separated by commas. They are output, separated by single spaces,
followed by a newline. The statement looks like this:

print ITEM1, ITEM2, ...
__________________
Jean-Pierre.
Reply With Quote
  #5 (permalink)  
Old 03-24-04, 12:36
amolbc amolbc is offline
Registered User
 
Join Date: Mar 2004
Posts: 7
Cool

Quote:
Originally posted by aigles
You can do it with 'awk'

Code:
awk ' {
   print substr($0,38,4) substr($0,25,1) # print [25][38-41]
   print substr($0,4,4),substr($0,1,2)   # print [4-7] [1-2]
} ' a.txt

$0
The record read from file

substr(STRING, START [, LENGTH])

This returns a LENGTH-character-long substring of STRING, starting
at character number START. The first character of a string is
character number one. For example, `substr("washington", 5, 3)'
returns `"ing"'.

If LENGTH is not present, this function returns the whole suffix of
STRING that begins at character number START. For example,
`substr("washington", 5)' returns `"ington"'. The whole suffix is
also returned if LENGTH is greater than the number of characters
character number one. For example, `substr("washington", 5, 3)'
returns `"ing"'.

If LENGTH is not present, this function returns the whole suffix of
STRING that begins at character number START. For example,
`substr("washington", 5)' returns `"ington"'. The whole suffix is
also returned if LENGTH is greater than the number of characters
remaining in the string, counting from character number START.

print statement

The `print' statement does output with simple, standardized
formatting. You specify only the strings or numbers to be printed, in a
list separated by commas. They are output, separated by single spaces,
followed by a newline. The statement looks like this:

print ITEM1, ITEM2, ...
Thanks a lot..this wudd help me....
i think i think of only in one direction....i was after cut only when awk is fit and happy to help me out..

now u go for replying my latest post..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On