How to cut line from certain position?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to cut line from certain position?
# 1  
Old 07-30-2013
How to cut line from certain position?

Hi Gurus,

I want to cut my file from 27th charactor to the end of line.

can anybody give some unix command to do this.

Thanks in advance
# 2  
Old 07-30-2013
Code:
cut -c 27- file

# 3  
Old 07-31-2013
u can use the command suggested by bartus11

Code:
cut -c 27- file

-c option is used to cut columns. give the starting column number from where you want to cut. you can specify a range using an hyphen(-).
for cutting a single column say only 27 use
Code:
cut -c 27 file

for cutting columns 27 to 31 use
Code:
cut -c 27-31 file

for cutting 27th and 29th column use
Code:
cut -c 27,29 file

for cutting columns from 27 till the last column an you dont know the column number then use
Code:
cut -c 27- file

if ypu dont specify the end column, it will cut till the line ends
if you want to cut from 1st column to 27th use
Code:
cut -c -27

# 4  
Old 07-31-2013
If this need is in sh-script then builtin substring is also usable.
Example:
Code:
while read line
do
      #substr index start 0
       endline=${line:26}
done < inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut command with dynamic passing of delimiter and position values

Hi All, We have a requirement of picking nth position value by using cut command. value would be delimited by any symbols. We have to pass delimited value and postition to get the value in a string. ex. echo "A,B,C,D,E" |cut -d "," -f3 echo "A|B|C|D|E"|cut -d "|" -f2 Kindly frame the... (5 Replies)
Discussion started by: KK230689
5 Replies

2. UNIX for Beginners Questions & Answers

Cut two individual position and summ

Hi All, I am having a huge file file. I need to cut the below column and do the below calculation I did the below command and able to do on full databased no on the individual based any help on doing each row by row cut -c 52-56 myfile | awk '{total = total + $1}END{print total}'... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

3. Shell Programming and Scripting

position of character in a line

i want to find the position of a character in a line , the first position, last, 5th occurence position , i ve tried grep -n , and expr index but they dont fit the bill. Please let me know if there is any other alternative (2 Replies)
Discussion started by: phpsnook
2 Replies

4. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

5. Shell Programming and Scripting

Cut multiple data based on character position

How to extract multiple data based on character position. I need to fetch from 7-9 and 22-26 and there is no delimiter for 22-26 since it is part of the column. The file may have more than 1000 character long.I managed to pull any one but not both for example test data 12345 zxc vbnmlk... (1 Reply)
Discussion started by: zooby
1 Replies

6. Shell Programming and Scripting

move to a particular position and line

Hi, How can i move to particular line and to a particular position in a file using unix commands ? eg: in the line 30 and position 10 i want to print my name in a file. Cheers, Mohan (1 Reply)
Discussion started by: mohanpadamata
1 Replies

7. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies

8. Shell Programming and Scripting

Cut position as a variable

Hi All, I wish to cut an input by using the below command but i would want to have the cut position as a variable. For eg, the position number is 11 now and i wish that this number is being assigned to a variable before putting into the cut function. Can this be done ? Can any expert help?... (1 Reply)
Discussion started by: Raynon
1 Replies

9. Shell Programming and Scripting

Cut output to same byte position

Hi folks I have a file with thousands of lines with fixed length fields: sample (assume x is a blank space) 111333xx444TTTLKOPxxxxxxxxx I need to make a copy of this file but with only some of the field positions, for example I'd like to copy the sample to the follwing: so I'd like to... (13 Replies)
Discussion started by: HealthyGuy
13 Replies
Login or Register to Ask a Question