Hi,
I have been thinking of how to script this but i have no clue at all..
Could someone please help me out or give me some idea on this?
I would like to group those lines with the same first variable in each line, joining the 2nd variables with commas.
Let's say i have the following input.
I would like the output to be like this.
Could this be easily done with bash script?
Or should i try perl script then?
I'm a beginner in bash script and perl.
Thank you.
***************************
Try this
This assumes that the input file is sorted.
********************************************************
Sorry.. don't understand..
what is a, b , F ..?
Anyway i found a short solution.
${input} is the filename for the input file.
I love the way that the first script uses Bourne echo and never terminates the last line.
The "short solution" relies on the exponential multi-pass technique and utilises a magic Shell with unlimited command line length. Until looking at unix.com I had never seen the for var in <open-ended list> construct ever ... and still wonder which course/manual/book/rumour it comes from?
Footnote: For anybody following this thread, this is a discussion thread.
@jgt is expert and definitely did not ask this question.
Footnote: For anybody following this thread, this is a discussion thread.
@jgt is expert and definitely did not ask this question.
I must confess that I was confused until that footnote clued me in to the fact that I wasn't in the shell scripting forum anymore (got here via the 'new posts' link).
Quote:
Originally Posted by methyl
Until looking at unix.com I had never seen the for var in <open-ended list> construct ever ... and still wonder which course/manual/book/rumour it comes from?
I don't know for certain, but my first impulse is to blame GNU Bash. I've seen that idiom recommended as the correct way to work around the fact that the final command in a bash pipeline runs in a subshell.
From the Advanced Bash-Scripting Guide's Bash Gotchas:
Regards,
Alister
@jgt
[..]The "short solution" relies on the exponential multi-pass technique and utilises a magic Shell with unlimited command line length. [..]
Although it may be good to note that command line length does not really play a role in this case, since "for" is a shell keyword and not an external command, so the length of the list should be more or less limited by memory...
Quote:
Originally Posted by alister
[..]I don't know for certain, but my first impulse is to blame GNU Bash. I've seen that idiom recommended as the correct way to work around the fact that the final command in a bash pipeline runs in a subshell[..]
It is not only bash, dash and Bourne shell do this too. It is also not specified by Posix, so ksh is the exception..
Last edited by Scrutinizer; 07-04-2012 at 06:42 PM..
Although it may be good to note that command line length does not really play a role in this case, since "for" is a shell keyword and not an external command, so the length of the list should be more or less limited by memory...
There have been so many posts from AIX users (to name but a few O/S versions and variants and for the benefit of @jlliagre that includes many versions of SunOS/Solaris!) who hit this problem that I would love that the for var in <open ended list> syntax would become a syntax error.
Somehow I knew that this thread was going to be fun.
It is not only bash, dash and Bourne shell do this too. It is also not specified by Posix, so ksh is the exception..
I agree with you. ksh is exceptional.
My post isn't intended to suggest that bash (or dash or bourne sh) violate the standard -- I'm aware that POSIX allows a shell to execute each component of a pipeline in either the current environment or a subshell (ksh is compliant in this respect); the post is merely a response to methyl's rumination on the popularity of the idiom, identifying one popular resource which promotes it.
In my opinion, the ksh approach makes life a little easier. But, if I depend on it in a script, I always explicitly require ksh in the shebang.
My post isn't intended to suggest that bash (or dash or bourne sh) violate the standard -- I'm aware that POSIX allows a shell to execute each component of a pipeline in either the current environment or a subshell (ksh is compliant in this respect); the post is merely a response to methyl's rumination on the popularity of the idiom, identifying one popular resource which promotes it.
You weren't that wordy about it at the time; you simply said your first impulse was to "blame GNU bash". That's a bit of a sore point -- BASH, as a shell many new users start with, has a low value in some admin's eyes -- the habit of new users calling all shell scripting "bash scripts" doesn't help -- and seems to get blamed for everything from their own bugs to poor weather as a result. Even though it's just doing what a Bourne shell does. Blame him if you must.
Quote:
In my opinion, the ksh approach makes life a little easier.
Perhaps, but it's not something that can really be changed now. Bourne is what it is, and changing the ordering would change what happens in a lot of scripts because it cuts both ways -- suddenly scripts could be setting variables in the main shell they never did before...
I bet BASH'll add it as one of it's many fiddly setopt options someday.
I have about 12,000,000 mod files I'm trying to turn into a test of "unlimited cloud storage" by running them all through VLC and blowing them into mp3 files. I can get this to work serially but when trying to use openMPI or Parallel, something in the syntax is tripping it up some. Here is an... (1 Reply)
Hi ,
I have a code where i am using a infinite while loop . some thing like below
while
do
if
then
#go to line 20
fi
command 1;
command 2;
#line 20:
sleep 34; (5 Replies)
Hi,
I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory.
finally {
if (null != hibernateSession && hibernateSession.isOpen()) {
//hibernateSession.close();
}
}
It would be great if the script has... (2 Replies)
hi all,
Can any 1 help me translate this korn shell code to C shell code :
email=$(grep "^$1" $folder/config_2.txt | awk '{print $2'})
In config_2.txt the content is :
which mean in korn shell , $1=groupname and $2=email address.
Now i need to write in C shell script,when i set the... (2 Replies)