Sponsored Content
Top Forums UNIX for Beginners Questions & Answers awk printing leading tab in output Post 303037324 by cmccabe on Monday 29th of July 2019 06:49:34 PM
Old 07-29-2019
awk printing leading tab in output

The awk below executes and produces the current output. it skips the header in row 1 and prints $4,$5,$6 and then adds the header row back.
The problem is that it keeps the tailing tab and prints it in front of $1. I could add a pipe to remove the tab, but is there a better way to do it with on command? Thank you Smilie.

File tab delimeted
Code:
Total_Targets	Targets_less_than250x	Percent_more_than250x
chr11	533813	3633	215009	2077	99.034
chr11	533814	3637
chr11	533815	3637
chr11	533816	3639
chr11	533817	3640
chr11	533818	3639
chr11	533819	3643

Current output
Code:
Total_Targets	Targets_less_than250x	Percent_more_than250x
   215009 2077 99.034

Desired output
Code:
Total_Targets	Targets_less_than250x	Percent_more_than250x
   215009 2077 99.034

awk
Code:
 awk 'NR>1{$1=$2=$3=""; print $0}FNR==1' file

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Printing problem - Vertical Tab

At work, when I issue: lpr -P$PRINTER -h filename the file always prints a line then does a vertical tab off that first line instead of starting the new line at left. It does this with every file I've tried, and I can't find any options that are set that would make things print this way. I... (2 Replies)
Discussion started by: scaredinjuly
2 Replies

2. Shell Programming and Scripting

printing portion of the output usind sed/awk

friends, i am a newbie in scripting. could someone help me in selecting only the last column of below ps command output ? mqm 14 16466 0 Sep 15 ? 0:01 /opt/mqm/bin/runmqlsr -r -m QMGR.INBOUNDSSL -t TCP -p 1415 -i 5.1.26.5 mqm 12 16700 0 Sep 15 ? 0:00... (4 Replies)
Discussion started by: unahb1
4 Replies

3. Shell Programming and Scripting

output - tab formatted - awk

Dear All, Good Day. I would like to hear your suggestions for the following problem: I have a file with 5 columns with some numbers in 16 lines as shown below. Input file: Col 1 Col 2 Col 3 Col 4 Col 5 12 220 2 121 20 234 30 22 9... (3 Replies)
Discussion started by: Fredrick
3 Replies

4. Shell Programming and Scripting

printing two values with TAB in between

Dear friends, I want to print variables' values in certain format where space between two values of variables is "a tab" I tried where I provided "tab" between two varibales. But when it print values on screen its giving me output without spaces in two values. Request you to help me in... (7 Replies)
Discussion started by: anushree.a
7 Replies

5. Shell Programming and Scripting

awk and leading zeroes

I have the following script that renames filenames like: blah_bleh_91_2011-09-26_00.05.43AM.xls and transforms it in: 91_20110926_000543_3_blih.xls for a in *.xls; do b="$(echo "${a}" | cut -d '_' -f4)" dia=`echo ${b} | cut -c9-10` mes=`echo ${b} | cut -c6-7` anio=`echo ${b} | cut -c1-4`... (4 Replies)
Discussion started by: Tr0cken
4 Replies

6. Shell Programming and Scripting

Help! Printing out CSV output from awk Pattern Match

Hi, I need to search for a word using Awk and print out the line the word is in and every line after the search phrase until I hit this #------------. Then I need to send it to a csv file. So basically the input file format is like this:... (1 Reply)
Discussion started by: An0mander
1 Replies

7. Shell Programming and Scripting

awk output seperated by tab

I am just trying to output the below awk separated by tabs. Thank you :). awk (added OFS as an attempt to itroduce tabs) awk '{split($5,a,"-"); OFS='\t' print $1,$2,$3,a}' file.bed > test.bed The awk runs and produces all the data in 1 field instead of 4 fields. current output ... (2 Replies)
Discussion started by: cmccabe
2 Replies

8. Shell Programming and Scripting

awk output is space delimeted not tab delimeted

In the below awk the output is space delimited, but it should be tab delimited. Did I not add the correct -F and OFS? Thank you :). The input file are rather large so I did not include them, but they are tab-delimeted files as well. awk awk -F'\t' -v OFS='\t' 'FNR==1 { next } > ... (2 Replies)
Discussion started by: cmccabe
2 Replies

9. Shell Programming and Scripting

awk to add tab to output of both conditions

In the below awk written by @RavinderSingh13 I have added a few lines and am trying to have the output be tab-delimited. The input is space-delimeted and the portion in bold seems to add a tab to the Not found but not the found. Thank you :). file1 One 1 Two 2 Three 3 file2 One 1... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

awk printing output to new line

Hi I have a file profile.txt with the below input: {"atgUserId":"736f14c4-eda2-4531-9d40-9de4d6d1fb0f","firstName":"donna","lastName":"biehler","email":"schoolathome42@live.com","receiveEmail":"y es"}, {"atgUserId":"c3716baf-9bf8-42da-8a44-a13fff68d20f","firstName":"Gilberto... (6 Replies)
Discussion started by: ankur328
6 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 06:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy