Multiple Commands in PS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple Commands in PS
# 1  
Old 08-22-2013
Multiple Commands in PS

I need to find in file where the record starts with "A,U,I,R" and their file name

Record will look like below

Code:
A|1|138||XXXX|XX|XX
U|2|XX|XX|XX|XX
R|3|EK|XX|XX|XX
D|4|TY|CC|CC|CC

Code:
find ./*.dat -exec egrep "^A|U|I|R" \; -exec cut -d'|' -f1,2 \; -exec sort -u {} /dev/null \;


But it does not return any values.

Last edited by Scott; 08-22-2013 at 12:03 PM.. Reason: Additional code tags; removed formatting within code tags
# 2  
Old 08-22-2013
The different -exec primaries are not piped into each other.

You can either pipe find into cut and sort or use a single -exec and have it run a simple shell script.

Regards,
Alister
# 3  
Old 08-22-2013
i put your data in fileA.dat:

Code:
$ find . -name '*.dat' -exec sh -c 'grep -He "^[AUIR]" "$@" | cut -d"|" -f1,2 | sort -u' _ {} +
./fileA.dat:A|1
./fileA.dat:R|3
./fileA.dat:U|2

You probably only need find if you're recursively searching subdirectories.

Code:
$ grep -e "^[AUIR]" *.dat | cut -d"|" -f1,2 | sort -u
fileA.dat:A|1
fileA.dat:R|3
fileA.dat:U|2
fileB.dat:A|1
fileB.dat:R|3
fileB.dat:U|2

This User Gave Thanks to neutronscott For This Post:
# 4  
Old 08-22-2013
Great!!!

Could you please explain this part
Code:
'grep -He "^[AUIR]" "$@"

and need of this
Code:
_ {} +

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Pass Multiple Commands and Open Multiple Xterms via PSS

Hello, I'm attempting to open multiple xterms and run a command as an SAP user via sudo using PSSH. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in to the servers in the file list, and SUDO to the SAP(ADM) user, but it won't do anything else... (11 Replies)
Discussion started by: icemanj
11 Replies

2. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

3. Shell Programming and Scripting

multiple commands

Hi, I have a flat file with delimitor as X'1F' Need to get a string from second line, third field. I have problem with the below command. Below command is not correct. value=`head -2 $file_name|tail -1|cut -f3 -d`echo -e "\037"`` problem is with ` please help me to resolve this. Is there... (5 Replies)
Discussion started by: rohan10k
5 Replies

4. Solaris

Help with executing multiple remote commands after multiple hops

Hi SSHers, I have embedded this below code in my shell script.. /usr/bin/ssh -t $USER@$SERVER1 /usr/bin/ssh $USER2@S$SERVER2 echo uptime:`/opt/OV/bin/snmpget -r 0 -t 60 $nodeName system.3.0 | cut -d: -f3-5` SSH to both these servers are public-key authenticated, so things run... (13 Replies)
Discussion started by: LinuxUser2008
13 Replies

5. Shell Programming and Scripting

multiple commands

Hi, I have multiple commands that i need to run daily on my Solaris servers and watch the output, and actually i do it as multi-tasking. I do not want to put all of them in the file, and run it, and get the entire output at one time. What i want is that it should ask for before it runs next... (5 Replies)
Discussion started by: john_prince
5 Replies

6. UNIX Desktop Questions & Answers

Multiple SQL Commands

Hello Experts !!! Im new to this so, please bear with me ! I have the following 2 sql statements create table CMD_NEW_USER as Select FD.EMPLOYEE, FD.PASTUSER, ..... FROM REPORTS FS, TASKLIST FD WHERE FS.EMPLOYEEID = FD.EMPLOYEEID ; create table CMD_OLD_USER as Select FD.EMPLOYEE,... (4 Replies)
Discussion started by: OMLEELA
4 Replies

7. Shell Programming and Scripting

Commands to multiple xterms

Hi, I need some help with sending commands to multiple xterms. What I do is ssh -Y to a remote box, and then open up 4 shells (csh) and on each one I run a different program in sequence -- one of them has 2, the first of which goes into the background and after you hit "enter" or "return" you get... (0 Replies)
Discussion started by: rmoriarty
0 Replies

8. UNIX for Advanced & Expert Users

multiple commands execution

Hi i have 3 sql scripts that need to be executed simultaneously, and independent of one another, how do i do that in Unix AIX 5.3 (1 Reply)
Discussion started by: yschd
1 Replies

9. Shell Programming and Scripting

How to do multiple commands:

NEVERMIND figured it out! (1 Reply)
Discussion started by: llsmr777
1 Replies

10. Shell Programming and Scripting

multiple sed commands

hello! I have a few sed commands sed '/^$/d' < $1 > tmp.t sed '/^ \{3,\}/d' < tmp.t > tmp1.txt ..... how can I write them in a single line? sed '/^$/d' < $1 > | '/^ \{3,\}/d' < $1 > tmp1.txt any idea? thanks. (5 Replies)
Discussion started by: george_
5 Replies
Login or Register to Ask a Question