Sponsored Content
Top Forums Shell Programming and Scripting grabbing more than one argument in a loop Post 302289749 by Intense4200 on Friday 20th of February 2009 10:47:21 AM
Old 02-20-2009
Quote:
Originally Posted by Shahul
Hi Intense

Could you please share you required output sample data with input file...
so that makes clear picture...

Thanks
Sha
ok thanks to everyone so far; bakunin for the loop/read help, and hard aix; using your examples made me realize I have an error in my C code.
a contingency I did not realize was a possibility, filtering stuff that should not be filtered. the orig sortlist2.txt file has 14655 entries to sort through so it is a long file.

Here is a different section from the sortlist2.txt file:
  • p2_6l_2_16_5/Anteros 1091470965
    p2_6j_10_8_4/Erekiteru 1091550399
    p2_6j_10_8_4/Sabre 1091566980
    p2_6k_12_11_4/Sabre 1091566980
    p2_6l_2_16_5/Sabre 1091566980
    p2_6j_10_8_4/Lucy 1091573700
    p2_6j_10_8_4/Ads 1091578595
    p2_6k_12_11_4/Ads 1091578595
    p2_6l_2_16_5/Ads 1091578595
    p2_6j_10_8_4/Alral 1091578662
    p2_6k_12_11_4/Alral 1091578662
    p2_6l_2_16_5/Alral 1091578662
    p2_6j_10_8_4/Galena 1091598651
    p2_6k_12_11_4/Galena 1091598651
    p2_6k_12_11_4/Zippy 1091648261 <----- my code and 'cut' doesn't
    p2_6l_2_16_5/Zippy 1091648261 <-----
    p2_6j_10_8_4/Mijual 1091648261 <----- take into account this situation
    p2_6j_10_8_4/Kaya 1091696023
    p2_6k_12_11_4/Kaya 1091696023
    p2_6l_2_16_5/Kaya 1091696023
    p2_6j_10_8_4/Sej 1091721803
    p2_6j_10_8_4/Dewsfanclub 1091728387


Here is an example how the filter should work:
  • p2_6l_2_16_5/Anteros 1091470965
    p2_6j_10_8_4/Erekiteru 1091550399
    p2_6j_10_8_4/Sabre 1091566980
    p2_6j_10_8_4/Lucy 1091573700
    p2_6j_10_8_4/Ads 1091578595
    p2_6j_10_8_4/Alral 1091578662
    p2_6j_10_8_4/Galena 1091598651
    p2_6k_12_11_4/Zippy 1091648261
    p2_6j_10_8_4/Mijual 1091648261
    p2_6j_10_8_4/Kaya 1091696023
    p2_6j_10_8_4/Sej 1091721803
    p2_6j_10_8_4/Dewsfanclub 1091728387


here is how the sortlist3.txt should look:
  • p2_6l_2_16_5/Anteros
    p2_6j_10_8_4/Erekiteru
    p2_6j_10_8_4/Sabre
    p2_6j_10_8_4/Lucy
    p2_6j_10_8_4/Ads
    p2_6j_10_8_4/Alral
    p2_6j_10_8_4/Galena
    p2_6k_12_11_4/Zippy
    p2_6j_10_8_4/Mijual
    p2_6j_10_8_4/Kaya
    p2_6j_10_8_4/Sej
    p2_6j_10_8_4/Dewsfanclub


and the rmlist.txt would have the removed entries to be used later with the rm command:

  • p2_6k_12_11_4/Sabre
    p2_6l_2_16_5/Sabre
    p2_6k_12_11_4/Ads
    p2_6l_2_16_5/Ads
    p2_6k_12_11_4/Alral
    p2_6l_2_16_5/Alral
    p2_6k_12_11_4/Galena
    p2_6l_2_16_5/Zippy
    p2_6k_12_11_4/Kaya
    p2_6l_2_16_5/Kaya


So from a C standpoint i would need to, if the previous logout is the same as the one currently being read, then isolate the name from the directory and compare names also.

so from bash i would need to replace the / with a space to create 3 arguments per line, do the comparisons. but keep the / in the outputted lists.

and finally here is how the sortlis2.txt is being generated:
Code:
#!/bin/bash

rm blahlist.txt;
for adirfile in `cat -s adir.lst`
do
   echo -e "\e[0m adding list from \e[31m $adirfile \e[36m\n\n";
   grep  -m 1 LogO $adirfile/* >> blahlist.txt;
done

   echo -e "sorting list...\n\r";
   sort -g -k 2 blahlist.txt > sortlist.txt;

   echo -e "removing grep data...\n\r";
   sed  's/:LogO//' sortlist.txt > sortlist2.txt;
   echo "$" >> sortlist2.txt;
   echo -e "\e[0m";

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Argument passing using for or while loop

Hi All, My query is as below: Am basically writing a parser script. My input file has got some variables which are populated by the calling program. callig program: fun1("cat","dog","cow") input.* argument first argument second I want to write a script that should give me... (4 Replies)
Discussion started by: jisha
4 Replies

2. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies

3. UNIX for Dummies Questions & Answers

Grabbing a value from an output file

I am executing a stored proc and sending the results in a log file. I then want to grab one result from the output parameters (bolded below, 2) so that I can store it in a variable which will then be called in another script. There are more details that get printed in the beginning of the log file,... (3 Replies)
Discussion started by: hern14
3 Replies

4. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

5. Shell Programming and Scripting

Grabbing Certain Fields

ok, so a script i wrote spits out an output like the below: 2,JABABA,BV=114,CV=1,DF=-113,PCT=99.1228% as you can see, each field is separated by a comma. now, how can I get rid of the first field and ONLY show the rest of the fields. meaning, i want to get rid of the "2,", and... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

7. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

8. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies

9. Shell Programming and Scripting

Grabbing fields with perl

I have several .csv files containing data like this: field_1;field_2;date;comment;amount; I want to extract the 3 last fields and load them in a database. my input_file = "/dir/file.csv"; my output_file = "/dir/file.sql"; open my $csv_file, '<', $input_file or die "Can't... (1 Reply)
Discussion started by: freddie50
1 Replies

10. UNIX for Dummies Questions & Answers

Change argument in a for loop

In a "for i in *FD.CPY do" loop, I need to change .CPY to .layout so the executed command would be reclay blahFD.CPY >blahFD.layout What do I need to do to modify a copy of i to use after the > symbol? TIA (5 Replies)
Discussion started by: wbport
5 Replies
All times are GMT -4. The time now is 12:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy