UNIX Scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX Scripting
# 15  
Old 02-06-2014
If you call it inefficient, I fully agree. As mentioned before, useless is a different thing. With your experience you should have noticed that the request for information was from a noob. By keeping it simple (but indeed not efficient) it is easier to understand. It would have been better if I had given the efficient solution as well. But in that case also more efficient solutions for data handling (like Perl) should be mentioned (without saying that shell scripting is useless for data handling)

and for your information, I never said this was hard for me to read :-)
# 16  
Old 02-06-2014
If you didn't know, "useless use of cat" is a fairly well-known phrase in Unix scripting.

Incidentally, in this case I don't think using a pipeline is simpler or easier to understand than just supplying the filename as a parameter...

Last edited by CarloM; 02-06-2014 at 09:31 AM..
# 17  
Old 02-09-2014
You may try:

sed -n '/^machine/p;/^Owner/p' infile

thanks
# 18  
Old 02-10-2014
(afaik)
Code:
egrep -A1  "^machine" script.txt > outputfile

should be the same as:
Code:
grep -e -A1  "^machine" script.txt > outputfile

You missed the -A1, as well as there is no need for [ICODE]cat[/ICODE] Smilie

Hope this helps
# 19  
Old 02-10-2014
Quote:
Originally Posted by sea
(afaik)
Code:
egrep -A1  "^machine" script.txt > outputfile

should be the same as:
Code:
grep -e -A1  "^machine" script.txt > outputfile

You missed the -A1, as well as there is no need for [ICODE]cat[/ICODE] Smilie

Hope this helps
Almost...
Code:
egrep ...

is the same as:
Code:
grep -E

on systems that both have egrep (which is now obsolescent) and have a -E option in grep (which some very old versions do not have).
# 20  
Old 02-14-2014
This will do the trick try it.

Code:
awk -F" " '/machine|Owner/ { print}' file


Last edited by Scott; 02-14-2014 at 08:40 AM.. Reason: Code tags
# 21  
Old 02-14-2014
Quote:
Originally Posted by ocrambo
In my opinion using `cat` as an example is easy to understand, so useful.
You are incorrect in several ways here.
  1. cat does not do anything here. Your scripts would do the same thing without it.
  2. cat is useless here. Your scripts would be shorter and simpler without it.
  3. cat is counterproductive here. Your scripts would be faster without it. If you ever put code like this inside a loop, UUOC will suddenly become important.
  4. You are limiting your options. Using cat means you can only read from stdin. This rules out a lot of fairly standard and useful awk constructs, etc.

That UUOC looks clearer to you means -- to be blunt -- that you should learn what shell scripts are supposed to look like, instead of relying on bad old habits.

If you really really want to, you can put redirection at the front too in most cases, to get the same 'benefit' without UUOC. <inputfile awk ...

Last edited by Corona688; 02-14-2014 at 12:08 PM..
These 3 Users Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX scripting

LIST=/home/xxxxxxx/ABC/xeeno_scrpts/temp/tempfile ERRORDIR=/home/xxxxxxx/ABC/error_directory EMAILFILE=/home/xxxxxxx/ABC/xeeno_scrpts/temp/emailfile echo "There were errors in the following report file for Xeenos:" > $EMAILFILE echo >> $EMAILFILE echo "This files have been moved to... (9 Replies)
Discussion started by: bcarosi
9 Replies

2. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

Hello Experts, I have the following questions to be discussed here at this esteemed discussion forum. I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies

3. UNIX for Advanced & Expert Users

Unix scripting

i need help with this problem this is the problem: Write a script that logs how many users login on/off the system over a 5 minute period. It can run in the foreground, and run 4 times a minute. Set a trap that will not allow a CNTRL-C command, and if a CNTRL-C is excuted store the time and date... (1 Reply)
Discussion started by: sportsmansixty6
1 Replies

4. Shell Programming and Scripting

Unix scripting

how to check if a unix script gets executed without errors across all unix platforms. incase if a script gets executed without errors only one platform say AIX, what needs to be done to that script such that it will run all unix platforms like linux, hp, sun etc (2 Replies)
Discussion started by: rmann
2 Replies

5. Shell Programming and Scripting

Unix Scripting

Hi Gurus, I am a system admin in solaris field and ive planned to study unix scripting.ive planned to start reading Mastering Unix scripting by randal.Scripts in that are based on Korn shell(ksh).my question is whether the same scripts can be applied to other shells like bash etc..And... (4 Replies)
Discussion started by: madanmeer
4 Replies

6. UNIX for Dummies Questions & Answers

Unix Scripting

Hi Gurus, I am a system admin in solaris field and ive planned to study unix scripting.ive planned to start reading Mastering Unix scripting by randal.Scripts in that are based on Korn shell(ksh).my question is whether the same scripts can be applied to other shells like bash etc..And... (1 Reply)
Discussion started by: madanmeer
1 Replies

7. UNIX for Dummies Questions & Answers

Unix scripting pl help

Hi All, I am new to Unix Scripting. I have below scenario. I need to write a Unix function with the following. 1. I have table. From this table I need to write a query. SELECT Col1(File_nm),Col2(From_Loc),Col3(To_Loc) FROM A WHERE CONDITION For... (1 Reply)
Discussion started by: sree11
1 Replies

8. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

9. UNIX for Dummies Questions & Answers

Help With Unix Scripting.

Can anybody tell me the best way to learn unix scripting.can you recommend a good book.Please help! (1 Reply)
Discussion started by: hella
1 Replies

10. UNIX for Dummies Questions & Answers

UNIX Scripting

:confused: I need to find a place or places on the Internet where I can find UNIX scripts to view and to modify to make life easy on the UNIX environment. Can someone help me on this. Thanks (7 Replies)
Discussion started by: wolf
7 Replies
Login or Register to Ask a Question