cut columns in everyline


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut columns in everyline
# 1  
Old 10-15-2008
cut columns in everyline

Is there a betterway to cut certain columns in everyline based on positions.

Basically, I have a largefile and eachline is of 1000 characters and I need to cut the characters 17-30, 750-775, 776-779, 780-805


while [ i -le $tempcnt ]
do
fptr=`cat $tempfile | head -$i | tail -1`
claimid=`echo $fptr | cut -c17-30`
memberid=`echo $fptr | cut -c750-775`
idtype=`echo $fptr | cut -c776-779`
orgid=`echo $fptr | cut -c780-805`
echo"$claimid | $memberid | $idtype | $orgid">>$misfile
i=`expr $i + 1`
done

Thank you
# 2  
Old 10-15-2008
You can replace this useless use of (cat/head/tail/echo/cut):
Quote:
Originally Posted by gunaah
fptr=`cat $tempfile | head -$i | tail -1`
claimid=`echo $fptr | cut -c17-30`
memberid=`echo $fptr | cut -c750-775`
idtype=`echo $fptr | cut -c776-779`
orgid=`echo $fptr | cut -c780-805`
echo"$claimid | $memberid | $idtype | $orgid">>$misfile
..by one line in awk:
Code:
awk >> $misfile -v v=$i 'NR==i{print substr($0,17,14), substr($0,750,26), substr($0,776,4), substr($0,780,29)}' OFS=" | "


Last edited by danmero; 10-16-2008 at 01:17 AM.. Reason: Remove extra "print" , mybad :)
# 3  
Old 10-15-2008
Thanks!

this one also works

cut -c17-30,750-775,776-780,781-805 $tempfile > $misfile
# 4  
Old 10-15-2008
This also work:
awk '{print substr($0,17,14), print substr($0,750,26),print substr($0,776,4), print substr($0,780,29)}' logfile
# 5  
Old 10-16-2008
Quote:
Originally Posted by gunaah
this one also works

cut -c17-30,750-775,776-780,781-805 $tempfile > $misfile
.. yes if you don't need OFS(Other Field Separator) in your output, and anyway you need another tool to get the line number.
Quote:
Originally Posted by gunaah
echo"$claimid | $memberid | $idtype | $orgid">>$misfile
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

--Parsing out strings for repeating delimiters for everyline

Hello: I have some text output, on SunOS 5.11 platform using KSH: I am trying to parse out each string within the () for each line. I tried, as example: perl -lanF"" -e 'print "$F $F $F $F $F $F"' But for some reason, the output gets all garbled after the the first fields.... (8 Replies)
Discussion started by: gilgamesh
8 Replies

2. Shell Programming and Scripting

Cut line from searched file if grep find neighbor columns

Hello All, While searching for the question, I found some answers but my implementation is not giving expected output. I have two files; one is sourcefile, other is named template. What I want to do is to search each line in template, when found all columns, cut the matching line from source... (4 Replies)
Discussion started by: baris35
4 Replies

3. Shell Programming and Scripting

How to append server name to everyline?

I am executing df -mP to see the disk utilization. I would like to append servername also to each and every line. df -mP | awk '{ print $1","$2","$3","$4","$5","$6 }' trying to add something like this df -mP | awk '{ print $1","$2","$3","$4","$5","$6","$hostname }' ... (1 Reply)
Discussion started by: lazydev
1 Replies

4. Shell Programming and Scripting

AWK command to cut the desired header columns

Hi Friends, I have a file1 i want to retrieve only the fields which have DEP,CITY,TRANS as headers in other file. Output: I want to give the input as DEP,CITY,TRANS column names to get the output. i used cut command .. but if i have 300 fileds it is more difficult to... (4 Replies)
Discussion started by: i150371485
4 Replies

5. Shell Programming and Scripting

sed cut columns

hello everyone ! i face the following problem as i use sed to ignore some columns of an output. the command i use is sed 's/^\(*\) \(*\).*/\1 \2/' as i only want the 2 first columns the command finger returns the problem is that for some lines the results are fine but for other lines... (8 Replies)
Discussion started by: vlm
8 Replies

6. Shell Programming and Scripting

CSV with commas in field values, remove duplicates, cut columns

Hi Description of input file I have: ------------------------- 1) CSV with double quotes for string fields. 2) Some string fields have Comma as part of field value. 3) Have Duplicate lines 4) Have 200 columns/fields 5) File size is more than 10GB Description of output file I need:... (4 Replies)
Discussion started by: krishnix
4 Replies

7. Shell Programming and Scripting

Cut columns with delimiter

HI, I have a file like below "103865","103835","Zming","","Zhu","103965","Sunnyvale","US", "116228","116227","Morlla","","Kowalski","113228","Paese "(Treviso)""IT" I want to validate the 7th column which is below. "Sunnyvale" "Paese In the above 7th column Paese is not ended with... (9 Replies)
Discussion started by: Krrishv
9 Replies

8. Shell Programming and Scripting

Awk new datetime everyline

Hi, I'm using awk in HP-UX machine which does not support systime(), strftime(). So to get the date time I was using : seq 1 100000 | awk ' "date +%Y%m%d%H%M%s" | getline curtime; print curtime }' However the above code gets the date only once, next time it is not updated. For... (2 Replies)
Discussion started by: Random_Net
2 Replies

9. UNIX for Dummies Questions & Answers

cut and paste columns using awk

Hi, Let's say that I have a file called table, I know that if I need to see a the second column for exampls I use: awk ' {print $2}' table.txt Is there anyway to use awk to actually cut a column and put it somewhere else in the table?:confused: (8 Replies)
Discussion started by: cosmologist
8 Replies

10. Shell Programming and Scripting

cut - columns with formatted Output

Hi I have the input file as below ***TEST10067 00567GROSZ 099 00567CTCTSDS90 ***TEST20081 08233GROZWEWE 00782GWERW899 ***TEST30088 08233GROZWEWE 00782GWERW899 I am finding the lines starting with *** and outputing as below TEST10067 TEST20081 TEST30088 I need a space between TEST1... (9 Replies)
Discussion started by: dhanamurthy
9 Replies
Login or Register to Ask a Question