LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-03-2009, 02:48 AM   #1
mayankmehta83
LQ Newbie
 
Registered: Dec 2009
Posts: 7

Rep: Reputation: 0
Question printing hh in hh:mm using "awk '{FS=":";print $1}'" misses first line of output!!


input -->
% cat file
11:30
12:20
13:10

unexpected output -->
% awk '{FS=":";print $1}' file
11:30
12
13

expected output -->
% awk '??' file
11
12
13

Please suggest what's wrong with the command. Thanks in advance.

Also consider,

% awk '{ if(NR>1) {FS=":";print $1} }' file
12:20
13

It is as if awk has decided not to work on 1st row of input supplied !!
 
Old 12-03-2009, 02:54 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi, welcome to LQ!

2 options.

Put
Code:
awk -F: '{....'
or
awk 'BEGIN{FS=":"}{ ... '
 
Old 12-03-2009, 02:55 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

awk -F: '{ print $1 }' infile

or

awk 'BEGIN { FS=":" } { print $1 }' infile

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
square brackets in output of "ps aux" not matching output of "ps -ejH" alirezan1 Linux - Newbie 14 07-14-2010 04:17 AM
"failed to execute child process" "Input/output error" fl.bratu Fedora 4 12-15-2008 04:03 AM
Feeding the output of "diff" or "cat" command to dpkg --purge kushalkoolwal Debian 9 06-19-2008 07:27 AM
upgrade to kernel 2.6.16.1 : "make bzImage" print "parse error" math_physics Red Hat 2 06-29-2007 11:04 PM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration