modifying a awk line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting modifying a awk line
# 1  
Old 09-14-2009
modifying a awk line

Hi,

I want to print specific columns (from 201 to 1001). The line that I am using is listed below. However I also want to print column 1. So column 1 and 201 to 1001. What modifcations do I need to make?

Code:
Code:
awk -F'\t' 'BEGIN {min = 201; max = 1001 }{for (i=min; i<=max; i++) printf "%s", $i (i < max ? FS : RS)}'  file > file2


Last edited by phil_heath; 09-14-2009 at 04:23 PM.. Reason: code tags, PLEASE!
# 2  
Old 09-14-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 03:14 PM ---------- Previous update was at 03:10 PM ----------

This prints COLUMNS (not rows): 201 to 1001.
Your question is confusing.
If you want to print column ONE as well:
Code:
awk -F'\t' 'BEGIN {min = 201; max = 1001 }{printf "%s" $1 FS; for (i=min; i<=max; i++) printf "%s", $i (i < max ? FS : RS)}'  file > file2

# 3  
Old 09-14-2009
hey im sorry

also the code does not work.
# 4  
Old 09-14-2009
hmm, it should. Do you really want to print COLUMNS not ROWS? That sounds a little bit strange, that you have a document with more than 1000 COLUMNS. Could you please provide an example of a line in your file?
# 5  
Old 09-14-2009
Quote:
Originally Posted by phil_heath
hey im sorry

also the code does not work.
sorry:
Code:
awk -F'\t' 'BEGIN {min = 201; max = 1001 }{printf "%s", $1 FS; for (i=min; i<=max; i++) printf "%s", $i (i < max ? FS : RS)}'  file > file2

# 6  
Old 09-14-2009
yeah there is thousands of columns and I want to print column 1 and 201 to 1001
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modifying bash script to take each line in a file and execute command

I need to modify a bash script to to take each line in a file and execute command. I currently have this: #!/bin/bash if ; then echo "Lipsa IP"; exit; fi i=1 ip=$1 while ; do if ; then rand=`head -$i pass_file | tail -1` user=`echo $rand | awk '{print $1}'` pass=`echo $rand | awk '{print $2}'`... (3 Replies)
Discussion started by: galford
3 Replies

2. Shell Programming and Scripting

Modifying file from command line using Perl

Hi all, I am having a slight issue updating a file using perl from the command line I need some help with. The item is: DATA_FILE_TYPE=FULL When I run the below command /usr/bin/perl -p -i -e "s/DATA_FILE_TYPE=/DATA_FILE_TYPE=APPEND/g" processfile.cfg It looks to be... (2 Replies)
Discussion started by: kstevens67
2 Replies

3. Shell Programming and Scripting

Awk: Modifying columns based on comparison

Hi, I have following input in the file in which i want to club the entries based on $1. Also $11 is equal to $13 of other record(where $13 must be on higher side for any $1) then sum all other fields except $11 & $13. Final output required is as follows: INPUTFILE: ... (11 Replies)
Discussion started by: siramitsharma
11 Replies

4. Shell Programming and Scripting

Modifying awk code to be inside condition

I have the following awk script and I want to change it to be inside a condition for the file extension. ################################################################################ # abs: Returns the absolute value of a number function abs(val) { return val > 0 ? val \ ... (4 Replies)
Discussion started by: kristinu
4 Replies

5. Shell Programming and Scripting

awk script for modifying the file

I have the records in the format one row 0009714494919I MY010727408948010 NNNNNN N PUSAAR727408948010 R007YM08705 9602002 S 111+0360832-0937348 I want to get it int the format 0009714494919I MY010727408948010 NNNNNN N PUSAAR727408948010 R007YM08705 9602002 S ... (2 Replies)
Discussion started by: sonam273
2 Replies

6. UNIX for Dummies Questions & Answers

Understanding / Modifying AWK command

Hey all, So I have an AWK command here awk '{if(FNR==NR) {arr++;next} if($0 in arr) { arr--; if (arr == 0) delete arr;next}{print $0 >"list2output.csv"}} END {for(i in arr){print i >"list1output.csv"}}' list1 list2 (refer to image for a more readable format) This code was submitted... (1 Reply)
Discussion started by: Aussiemick
1 Replies

7. Shell Programming and Scripting

Modifying data within the same line

My file looks like this But I need to move the frequency value (Freq) to the second position, leaving intact the numbers at the top. The resulting file should look like this Thanks in advance! (3 Replies)
Discussion started by: Xterra
3 Replies

8. UNIX for Dummies Questions & Answers

Modifying a particulae data in a line contained in File

Hi, I have a file containing data: systemname/userid/password/comment systemname1/userid1/password1/comment1 systemname2/userid2/password2/comment2 I want to modify the "password" using script. Can anybody help me with this problem?:confused: (2 Replies)
Discussion started by: pgarg1989
2 Replies

9. Shell Programming and Scripting

Modifying a line

Hi, I am having trouble modifying this line. It is because there is a space that I dont know how to deal with. So the file looks like this >YM4911-Contig4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX >YM4915-Contig5 MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM There are two spaces between contig#... (6 Replies)
Discussion started by: phil_heath
6 Replies

10. Shell Programming and Scripting

awk modifying entries on 2 lines at 2 positions

Hi this script adds text in the correct place on one line only, in a script. awk 'BEGIN{ printf "Enter residue and chain information: " getline var < "-" split(var,a) } /-s rec:/{$7=a; } {print}' FLXDOCK but I need the same info added at position 7 on line 34 and... (1 Reply)
Discussion started by: gav2251
1 Replies
Login or Register to Ask a Question