Modifying the shell script to select pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modifying the shell script to select pattern
# 1  
Old 02-10-2015
Modifying the shell script to select pattern

Hello,
I have script which work 70% of the desired task [1], the output from script.sh is following [2], however the desired output I require is following [3].

Any piece of suggestion would be great..

thanks in advance,
emily

[1]
Code:
#!/bin/bash                                                                                                                                                                
PATHNAME=$1
CONSTANT=rfio:
GREP=$2
OUTPUT=$3

voms-proxy-init --voms cms:/cms/dcms

echo "Copying \"$1 | grep $2\" to $3"                                                                      
srmls "$PATHNAME" | grep "$2" | awk '{print string path $2}' string="" path=""  > "$3"

echo "progressing ... please be patient...

"[2]
Code:
/pnfs/desy.de/cms/tier2/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_199.root
/pnfs/desy.de/cms/tier2/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_746.root
/pnfs/desy.de/cms/tier2/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_92.root

[3]
Code:
/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0\
to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_199.root
/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0\
to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_746.root
/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0\
to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_92.root


Last edited by rbatte1; 02-10-2015 at 12:53 PM.. Reason: Tightened CODE tags
# 2  
Old 02-10-2015
Hello emily,

Can I check the logic rules you want to apply first? I think that you want to take each record and:-
  • remove the first four directory layers
  • split the line after ....Winter15_FlatPt-0 adding in a backslash
I regret that I do not know srmls as a command. Is this another script?


Robin
# 3  
Old 02-10-2015
First, you want to chop off 3 dirs; cut, sed, awk or even just shell pattern chopping (${name#pattern}, ${name%%pattern} ) can do this.

Second, you want to add a line break before 'to200', and again, sed, awk or shell pattern chopping. See man bash look for %%:
Quote:
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the
pattern matches the beginning of the value of parameter, then the result of the
expansion is the expanded value of parameter with the shortest matching pattern
(the ``#'' case) or the longest matching pattern (the ``##'' case) deleted. If
parameter is @ or *, the pattern removal operation is applied to each positional
parameter in turn, and the expansion is the resultant list. If parameter is an
array variable subscripted with @ or *, the pattern removal operation is applied to
each member of the array in turn, and the expansion is the resultant list.

${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expansion. If the
pattern matches a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with the shortest match-
ing pattern (the ``%'' case) or the longest matching pattern (the ``%%'' case)
deleted. If parameter is @ or *, the pattern removal operation is applied to each
positional parameter in turn, and the expansion is the resultant list. If parame-
ter is an array variable subscripted with @ or *, the pattern removal operation is
applied to each member of the array in turn, and the expansion is the resultant
list.
The sed/awk '.*' is always aggressive, but the pattern chop allows you to select aggressive or minimal wild card. I faintly recall MULTICS qedx or Waterloo FRED allowed you to select, too.

My mnemonic for remembering them is "#" is pound like 'pound on the nose", and '%' is like for a broker or artistliving off royalties, 'take my percentage at the end'.
This User Gave Thanks to DGPickett For This Post:
# 4  
Old 02-10-2015
DGPickett, your mnemonics are great!
# 5  
Old 02-10-2015
My guess for the splitting requirement is lines are to be split with "\" if they exceed 170 characters.

This could be achieved with:

Code:
srmls "$PATHNAME" | sed -En -e 's:^(/[^\/]+){4}::' -e "/$GREP/"'s/.{170}/&\\\n/gp'


Last edited by Chubler_XL; 02-10-2015 at 04:13 PM..
# 6  
Old 02-11-2015
I had it explained that in monetary values, the pound sign (okay, that's £ not #) goes at the beginning and working with percentages, the % goes at the end.

Pardon me for being picky about the British pound £. The # is a hash.



Robin - British, in case you couldn't guess!
# 7  
Old 02-12-2015
Well, # is just pounds of weight, force, mass, but the funky elle is pounds sterling. Is the price of silver really tied to it? Let me check my Yahoo finance metals prices! $16.95 an ounce is $271.20 / # with the GBP at $1.5364, 17651 % inflation!

Last edited by DGPickett; 02-12-2015 at 12:12 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

2. Shell Programming and Scripting

Modifying/Adding in the DNS server entry using shell script

Dear Experts. I need to add/modify the entries in the DNS server and this has to be achieved using shell script and below is the requirement, could you please let me know if a shell script can be written for this task? 1. Log in to primary DNS server 2. Check /etc/named.conf if zone is... (4 Replies)
Discussion started by: VKIRUPHAKARAN
4 Replies

3. Shell Programming and Scripting

How to print the output of a select query using shell script?

HI, I want to connect to database and fetch the count from a table. The sql query is as below : select count(*) from table_test where test_column='read'; How can I print the output of this statement using shell script. Thanks in advance. (4 Replies)
Discussion started by: confused_info
4 Replies

4. Shell Programming and Scripting

Modifying contents of the file in shell script

Hello all, I have a Kconfig file that looks like something below ... ================================ menu "Application type" config GUI_TYPE_STANDARD bool "Standard Application" source "cfg/config/std.in" source... (12 Replies)
Discussion started by: anand.shah
12 Replies

5. Shell Programming and Scripting

Execution problem with shell script for modifying a user

#/bin/sh echo "enter the user name" read $username echo "Enter new home directory" read $newhd usermod -d $newhd $username ;; error while executing : enter the user name Rev Enter new home directory: /home/58745 usermod: option requires an argument -- 'd' Try `usermod --help' or... (2 Replies)
Discussion started by: Revanth547
2 Replies

6. Shell Programming and Scripting

Select combination unique using shell script

Hi All, bash-3.00$ gzgrep -i '\ ExecuteThread:' /******/******/******/******/stdout.log.txt.gz <Jan 7, 2012 5:54:55 PM UTC> <Error> <WebLogicServer> <BEA-000337> < ExecuteThread: '414' for queue: 'weblogic.kernel.Default (self-tuning)' has been busy for "696" seconds working on the request... (4 Replies)
Discussion started by: osmanux
4 Replies

7. Shell Programming and Scripting

How to use select into command in shell script?

I need to get total number of rows in a table by using select count(*) from table and need to assign into a variable in shell script. I used the following script, it does return the number of rows but also with oracle headers, Please help me to eliminate this headers. Shell Script #!/bin/sh... (16 Replies)
Discussion started by: vel4ever
16 Replies

8. UNIX for Dummies Questions & Answers

Modifying a shell script without using an editor

Hi all, I really wan't to know that how to edit a shell script with out using an editor.. Is there any command? (4 Replies)
Discussion started by: buddhi
4 Replies

9. Shell Programming and Scripting

using SELECT sql statement in shell script

Hi there I have a database on a remote box and i have been using shell script to insert data into it for example, i could have a script that did this SN=123456 n=server1 m=x4140 sql="UPDATE main SET hostname='$n',model='$m' WHERE serial='$SN';" echo $sql |/usr/sfw/bin/mysql -h... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

10. Shell Programming and Scripting

Modifying a csv file from Shell Script

Hi all, I have some script that creates a temp csv file. What I need to do is do some search and replace and modify the file from my shell script. I know the commands to open the file and then apply the reg ex but wasnt sure how I could do this from a script and modify the file? Any help... (2 Replies)
Discussion started by: not4google
2 Replies
Login or Register to Ask a Question