awk - $9 and onwards


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers awk - $9 and onwards
# 1  
Old 03-24-2019
awk - $9 and onwards

How can I get awk to print all fields from $9 and onwards?
# 2  
Old 03-24-2019
Hi, try
Code:
awk '{sub($1".*"$8, ""); print}'

--- Post updated at 22:39 ---

else maybe
Code:
awk '{sub($1 ".*" $8 FS, ""); print}'

--- Post updated at 23:02 ---

Code:
awk '{sub(".*" $8 FS, ""); print}'

--- Post updated at 23:17 ---

It must be admitted that the above examples will work only if the content of the 8 fields will not be repeated in subsequent ones.
Code:
awk '{for (i = 9; i <= NF; i++) printf $i FS}'

--- Post updated at 23:26 ---

If the delimiter of the fields are whitespace is better to use sed
Code:
sed -r 's/(\S+\s+){8}//'

If the field separator is a comma then ...
Code:
sed -r 's/([^,]+,){8}//'


Last edited by nezabudka; 03-24-2019 at 04:54 PM..
# 3  
Old 03-24-2019
Quote:
Originally Posted by locoroco
How can I get awk to print all fields from $9 and onwards?
Hi locoroco,
The answer to your question really depends on what your field separator is, whether or not any of the first eight fields are empty, whether or not you need to maintain the exact text (including the input field separators) between the remaining fields when you print the results, and what version of awk you're using. Since we don't know the answers to any of the above questions, we can only make wild guesses.

The suggestions nezabudka provided might or might not work depending on the above unspecified constraints (and on the contents of various fields).

When starting a thread here, please always tell us what operating system you're using, what shell you're using, give us a complete description of what you're trying to do, give us a short sample input file and the exact output you hope to produce from that input, and show us what you have tried to do to solve the problem on your own.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

2. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

4. Shell Programming and Scripting

Need to check a file from a certain position and date onwards

Hi Guys, I need some advice please. My script is not grabbing information from a text file from a certain date correctly. It seems to be grabbing everying in the file, i know it is something simple but i have looked to hard and to long, to know what the issue is. Script awk '... (9 Replies)
Discussion started by: Junes
9 Replies

5. Shell Programming and Scripting

Need to check a file from a certain position onwards

Scripting Guru's, I need your help, can you tell me how i can check a file from a certain point onwards via a ksh script. Currerntly i am checking the whole file and can't script it so it checks from 17.01.2012 20:00:00 onwards please.. Any help will be greatly appericated. See file... (10 Replies)
Discussion started by: Junes
10 Replies

6. Shell Programming and Scripting

Sort a file from specific row onwards

Hello All: I've file in below format. File name is "FIRSTN.TBL": AAAAAA N BBBBBBBBBBBBBBBBBBBBBBB N . . . . ZZZZZZZZZZZZZZZZZZZZZZZZZZ N My file row length is 40 characters and my second column will start from 25th column and it is only... (3 Replies)
Discussion started by: nvkuriseti
3 Replies

7. Shell Programming and Scripting

Extracting log entries from a date onwards

One of the log file looks like entries as below. Wed Apr 6 14:51:18 2011 FAIL LOGIN: Client "9.191.21.54" Wed Apr 6 14:52:53 2011 CONNECT: Client "9.191.21.54" Wed Apr 6 14:52:54 2011 OK LOGIN: Client "9.191.21.54" Wed Apr 6 14:55:10 2011 CONNECT: Client "9.191.21.54" Wed Apr 6... (2 Replies)
Discussion started by: rijeshpp
2 Replies

8. Shell Programming and Scripting

Remove 3rd and onwards occurances of a character

I have a file with "@" in every line fdgfgddfg@sfsdfdsf@dfdfd@@vfdfsdfd@ sfsdfs@sdfd@gfhfgh@@ddffg@sdf@ srfgtfsdfs@sdfertrd@eergfhfgh@@ddffg@sdf@ wttrtrt@sdfd@sdfdf@@sdfdfds@@@ I need to remove all the fourth and onwards occurences of "@". so my final o/p would be fdgfgddfg@sfsdfdsf@dfdfd@... (7 Replies)
Discussion started by: Shivdatta
7 Replies

9. Shell Programming and Scripting

Print from second column onwards if $1<=40 using awk

I have a file like below 10 10 21 32 43 54 20 10 25 36 47 58 30 19 20 31 42 53 40 10 24 35 46 57 50 10 28 39 40 51 I need to check if $1 <= 40, then print from $2 onwards. If $1 > 40, the line is not printed. So I would have an output like this 10 21 32 43 54 10 25 36 47... (10 Replies)
Discussion started by: kristinu
10 Replies

10. UNIX and Linux Applications

Replace string in unix from 10th column onwards

Hi All, I need to replace the last 19 bytes of the following string My_Org_Testing_20090102_231124.txt (Text_Date_Time.txt). I would like to derive the current time using "date +%Y%m%d_%H%M%S.txt" and replace the last 19 bytes of the above string I would appreciate if someone could... (3 Replies)
Discussion started by: rpk2008
3 Replies
Login or Register to Ask a Question