...
I got the idea because while read works line by line from the beginning of the file the swapped line is always located behind the other one so if I remove it read will never see it. But apparently the entire original file is still available to read no matter what I remove.
Is there is a better approach?
You might want to read the input data into several variables, not just the one $LINE. Like while read V1 DIR1 DIR2 V2, and the operate on the two DIR variables...
I also modified my script to avoid duplicates in the first place, using an array to save filenames and compare them to incoming new ones.
It is reassuring that the results are the same as with awk '!A[$2,$3]++ && !A[$3,$2]++' file.
Now spending some time with awk to figure out what that actually does...
--- Post updated at 10:00 PM ---
Quote:
Originally Posted by Scrutinizer
Assuming the fields in your input file are whitespace separated, you could try this approach:
Hm...
I converted this, with some trial and error, into what I think an awk program would look like:
Two questions:
1) If I keep the A[$2,$3] and A[$3,$2] then the output produces a funny character between the two filenames but the command line version works fine. What is the problem?
2) How does the command line version know to print only those keys (i) for which the count is 1?
I'm using GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.2)
(I'll figure it out somehow but it's getting late and it doesn't hurt to ask.)
Thanks.
awk does not print a key equal to 1. It's print when the key is zero. Post increment ++
Value is first equal to 0 and then 1, 2, etc.
0 == fals == no print
1 == true == print
but the sign of inversion ! makes so
!0 == true == print
!1 == false == no print
!2 == false == no print
when you enclose the script in brackets you can not put an inversion sign
In the body it does not work
Last edited by nezabudka; 12-18-2018 at 08:20 AM..
Assuming the fields in your input file are whitespace separated, you could try this approach:
Quote:
Originally Posted by nezabudka
awk does not print a key equal to 1. It's print when the key is zero. Post increment ++
Value is first equal to 0 and then 1, 2, etc.
0 == fals == no print
1 == true == print
but the sign of inversion ! makes so
!0 == true == print
!1 == false == no print
!2 == false == no print
The keys are '$3,$2' and '$2,$3'. Right? The values after the entire file has been processed are either 2 or 1.
What I mean is when I leave out the END block nothing get's printed.
What awk program will deliver the same result as the one-liner awk !A[$2,$3]++ && !A[$3,$2]++ file ?
The keys are '$3,$2' and '$2,$3'. Right? The values after the entire file has been processed are either 2 or 1.
What I mean is when I leave out the END block nothing get's printed.
What awk program will deliver the same result as the one-liner awk !A[$2,$3]++ && !A[$3,$2]++ file ?
(I suspect I'm missing something obvious.)
You would need to leave out the braces:
Everything in awk has the form condition{action}. If the condition evaluates to 1 then the action is performed. If the condition is omitted then the default condition is 0, so the action is not performed. If the action is omitted then - if the condition is 1 - the default action is performed, which is {print $0}, which is "print the record", by default a line of the input file.
Since there is just a condition with the default action, in this case there are no braces.
Last edited by Scrutinizer; 12-18-2018 at 10:20 PM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
1. increase file space
first, double space a file:
awk '1;{print ""}'
I probably can understand it:print a blank line every time.But when I read triple space a file I am confused:
awk '1;{print "\n"}'
doesn't it meaning print a blank line every time too?
2. number each line of file, but... (6 Replies)
Hi,
I ran a script named cat item
when I searched for this script using command PS
I get two process . I don't understand this. Also this script has run for 15 minutes but the time is showing as 0:00:confused::confused:
ps -ef | grep cat_item
catmgr 4508 4486 0 05:10:29 ? 0:00... (5 Replies)
I'm trying to extract a subject from a mail message but my subject example has 2 lines. How can I manage to extract it and write a string at the end of it?
Consider this example:
From: test@domain.com
Subject: Re: U =?ISO-8859-1?Q?qu=EA=3F!=3F!=3F!!_wtff_=E7=E3o_=ED=F3?=
... (6 Replies)
Sed garbled error. Cannot determine why the sed command to insert a line at the beginning of a file will not work on declared variables.
outfile='DAR.V2.2012115.1.CSV'
testfile='totality_request.sql'
header_prefix='DATA FILE'
no_ext_file=`echo $outfile |sed 's/\(.*\)..../\1/'`
... (6 Replies)
Hi,
I am a little bit confusing of using find command.
Actually, I am planning to delete the files whatever the files are existing in the day before yesterday. So, I am writing the command like this.
find . -name "*.txt" -ctime -2 { here I am confusing, if I will use +2 or +1 also I am... (5 Replies)
I am looking at installing PiKdev which needs libqt3-mt and kdelibs4-dev. The installed package is qt-r1008952-i486-1 which claims to be a gui toolkit. find / -name "*libqt*" yields nothing with mt just a lot of support, compatible, and access widgets. Normally I would consider this a no go but... (0 Replies)
Hiii... There...
I am making a Script in which I am taking the value of a variable "var"
through key board.
But I want, if no values are supplied for "var" for more than 5 seconds then script shuld automatically exit.Script is as follow :
#cat abc
#!/bin/bash
echo "Enter Your Choice : "... (4 Replies)
Hi all,
Just subscribed to this forum. Not a regular user of Unix.:)
I did the following:
We have a directory structure /a/b/c5/
Where c5 is the only directory inside b.
export ANOOP=/a/b/c*/
echo $ANOOP=/a/b/c5/
I have to create a symbolic link to anoop.txt in the directory... (2 Replies)
Hi All,
Very need help about format syntax on solaris 10.
I have done install Solaris 10 OS on sun fire v245 but currently i have a problem to use "format" command to display partition info for my hard drive.
i cannot enter the format menu, below is captured display :
# format
Searching... (7 Replies)