Sponsored Content
Top Forums UNIX for Dummies Questions & Answers [awk] print from field n to field x Post 302356174 by daPeach on Thursday 24th of September 2009 07:08:21 PM
Old 09-24-2009
Hi vgersh99,

I'm sorry, although all seem to have to work, it doesn't.
If I let it as it is, I get:
Code:
awk '{for (i=1; i <= 4; i++) printf("%s%c" $i, (i==4)?ORS:OFS)}' awkTest.dat
awk: (FILENAME=awkTest.dat FNR=1) fatal: not enough arguments to satisfy format string
    `%s%ca'
       ^ ran out for this one

If I only use 'string' or 'ascii', here's what I get, for example, with %c (it's the same with %s):
Code:
awk '{for (i=1; i <= 4; i++) printf("%c" $i, (i==4)?ORS:OFS)}' awkTest.dat
 a b c
d a b c
d

fyi
Code:
awk --version
GNU Awk 3.1.5
Copyright © 1998, 1991-2005 Free Software Foundation, Inc.


Last edited by daPeach; 09-24-2009 at 08:16 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

2. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

3. UNIX for Dummies Questions & Answers

Print first field in awk

Hi, I have below text file 01.02.2014,asdas,arse,aere,4tfsd 12.03.2014,sdte,45gf,8iuj,qw343w 01.02.0214,aetre,sdfgter,asfrwe I have writen below code to print only first field that is only date field from text file #!/bin/ksh echo "enter week" read week while read -r... (6 Replies)
Discussion started by: stew
6 Replies

4. UNIX for Dummies Questions & Answers

Print first field using awk

I want to print line by line only the first field from txt file input file etr,t7tu,e45xdt,e45exgt,cdgfe aqw34aw,45edgf,45estd,sert34 a232e,4etedf,w345er,qw345rw, qw354,q34asf,tw45f,q3drsf required o/p file etr aqw34aw a232e qw354 (1 Reply)
Discussion started by: stew
1 Replies

5. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

6. Shell Programming and Scripting

awk to parse field and include the text of 1 pipe in field 4

I am trying to parse the input in awk to include the |gc= in $4 but am not able to. The below is close: awk so far: awk '{sub(/\|]+]++/, ""); print }' input.txt Input chr1 955543 955763 AGRN-6|pr=2|gc=75 0 + chr1 957571 957852 AGRN-7|pr=3|gc=61.2 0 + chr1 970621 ... (7 Replies)
Discussion started by: cmccabe
7 Replies

7. Shell Programming and Scripting

How can awk ignore the field delimiter like comma inside a field?

We have a csv file as mentioned below and the requirement is to change the date format in file as mentioned below. Current file (file.csv) ---------------------- empname,date_of_join,dept,date_of_resignation ram,08/09/2015,sales,21/06/2016 "akash,sahu",08/10/2015,IT,21/07/2016 ... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

8. Shell Programming and Scripting

awk to adjust coordinates in field based on sequential numbers in another field

I am trying to output a tab-delimited result that uses the data from a tab-delimited file to combine and subtract specific lines. If $4 matches in each line then the first matching sequential $6 value is added to $2, unless the value is 1, then the original $2 is used (like in the case of line... (3 Replies)
Discussion started by: cmccabe
3 Replies

9. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 07:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy