Sponsored Content
Top Forums Shell Programming and Scripting Combine awk commands into one Post 302979708 by bakunin on Thursday 18th of August 2016 05:56:08 AM
Old 08-18-2016
As a general remark about one-liners: one-liners reduce readability and understandability. Their advantage is that they can be fastly written.

Given that you are unable to modify your already existing one-liners (which i take as a hint that you are not completely understanding them already) i suggest that it is a bad idea to combine these to an even more complex construct which you are bound to understand even less.

It is of course always possible to rely on us (or other people like us) to provide modifications as the code will need to be modified but, honestly: do you really want to preside over an environment where you do not understand what is going on? It might be me but i for my part would have a very bad feeling being in such a position.

It is in your own best interest if you rely on us only if you need an explanation to further your understanding but not to write or modify your productive code. Whatever you use finally you should be able to produce on your own and you should write it in a way that you are able to understand its inner workings.

Btw., over time i found that restricting my written code to 80 characters per line with only select few exceptions (for instance definitions of string constants) makes my code more readable and better overall. The reason is that a line containing more than 80 characters is most likely badly formed and should be rewritten in a more conclusive manner anyways. This in most cases means i reformat one-liners to their long form.

Here is an example where i filter out comments and whitespace from an input file before processing:

Code:
sed 's/#.*//;s/^[ 	]*//;s/[ 	]*$//;/^$/d' "$fCmd" | while read chCmd ; do
     .....
done

Going over that code i modified it to:

Code:
sed 's/#.*//
     s/^[ 	]*//
     s/[ 	]*$//
     /^$/d' "$fCmd" |\
while read chCmd ; do
     .....
done

I'd say the second variant gives you a much cleaner and easier to grasp impression of what is going on than the first.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine Two Commands Output

How i can combine output of two commands in one file.......i tried this but it is not working although each command is working good seperately..... head -1 filename | tail -1 filename i think there is problem with command concatenator? (16 Replies)
Discussion started by: 33junaid
16 Replies

2. UNIX for Dummies Questions & Answers

Combine commands

Hi, i tried to combine grep with find and it didnt work grep 'find dirname filename" i also would like that the file will be sorted in the way. thanks a lot. (2 Replies)
Discussion started by: Spoiler
2 Replies

3. Shell Programming and Scripting

nawk, combine commands

How would I combine two nawk commands together without calling up nawk twice. Just like the sed -e command nawk '$3>=from&&$3<=to' from="$STIME" to="$ETIME" | nawk '{$5="";$6=""}1' (2 Replies)
Discussion started by: numele
2 Replies

4. Shell Programming and Scripting

Can I combine these two commands into one?

sed -e :a -e 's/<*>//g;/</N;//ba' a2.html -removes html tags and sed -i 's/YOURS TRULY/Joe Bob/' a2.html Replaces a string with another string can i make it into one string? (2 Replies)
Discussion started by: boyboy1212
2 Replies

5. Shell Programming and Scripting

How to combine awk and bash commands in script ?

Dear friends, I am just trying write one script using 2 files one file will contain details like below #X SERVER X LOCATION URL="http://www.abcd.com" FILENAME="abc.txt" ID_NAME="myabc_xyz" SERVER_PATH="/usr/local/dummy/html/....." #Y SERVER Y LOCATION URL="http://www.xyz.com"... (10 Replies)
Discussion started by: Akshay Hegde
10 Replies

6. Shell Programming and Scripting

Combine multiple awk commands

Hi Team, I am getting input like below $ ps -ef | grep pmon | grep -v asm | grep -v grep oracle 3246 1 0 00:03 ? 00:00:01 ora_pmon_racora1 oracle 4367 1 0 00:03 ? 00:00:01 ora_pmon_test1 oracle 6893 1 0 00:03 ? 00:00:01 ora_pmon_gipora1... (6 Replies)
Discussion started by: kamauv234
6 Replies

7. Shell Programming and Scripting

Pipe or combine output of three awk commands

What is the correct syntax to pipe or run three awk commands? Basically, using the output of the first awk as input in the second. Then using the output of the second awk in the third. Thank you :). awk 'FNR==NR {E; next }$3 in E {print $3, $5}' panel_genes.txt RefSeqGene.txt > update.txt |... (3 Replies)
Discussion started by: cmccabe
3 Replies

8. Shell Programming and Scripting

Combine multiple commands

I have the following sh-script: konsole -T todo -e vi todo.txt & konsole -T window1 -e ssh user@server & konsole -T window2 -e ssh user@server2 -e cd directory & The first two lines are working fine. The first opens a txt-file, the second opens a ssh-connection. The third line... (6 Replies)
Discussion started by: andre666
6 Replies

9. Shell Programming and Scripting

Combine two awk commands

Hi, Can someone please guide me how to combine the following two awk calls in one? I noticed that it is very often situation for me, and I think that it can be replaced with one awk call. The question is more general, not the exact one. echo "A B C/D" | awk '{print $3}' | awk -F/ '{print... (4 Replies)
Discussion started by: mirusnet
4 Replies

10. Shell Programming and Scripting

Combine 2 Commands

Hello, I have the following code. I wonder if it can be combined into 1 command. y=`ls -1| tail -n 1` m=${y%.abc} Thank you. (3 Replies)
Discussion started by: april
3 Replies
deweb(1)						      General Commands Manual							  deweb(1)

NAME
deweb - strips away C & CWEB commands from CWEB sources SYNOPSIS
deweb [ file1 file2 ... ] DESCRIPTION
deweb filters away all C & CWEB commands from a CWEB source code. This leaves only the LaTeX code. This stripped code, in turn, may then be passed to a suitable syntax checker for LaTeX, like ChkTeX and lacheck, or spell-checkers like ispell. The chkweb tool, included in the ChkTeX distribution will do just this; writing similar scripts should be trivial. When deweb strips away the C code from your CWEB source, it tries to preserve line breaks. This means that the error reports from <your favorite tool> will be correct regarding to line numbers. In most cases, the column position will also be correct. This significantly sim- plifies finding the errors in the LaTeX source (in contrast to the output from cweave, which output is truly difficult to figure anything out from). deweb accepts a list of filenames on the argument line, and will send its output to stdout. If no filenames are given, it will read from stdin, acting as a filter. No options are currently accepted. Macho users may try to pipe the output from deweb directly into LaTeX, theoretically, this should work. This would ease the debugging of the LaTeX code significantly, as when LaTeX complains about wrong syntax, you'll be able to find the erroneous line much more easily. Don't expect that the output looks very much like the final one, though. deweb should now understand all correct CWEB opcodes. If it complains about not understanding a correct opcode, please inform the author. DISTRIBUTION
Copyright (C) 1996 Jens T. Berger Thielemann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ENVIRONMENT
No environment variables are used. FILES
None. AUTHOR
Jens T. Berger Thielemann, <jensthi@ifi.uio.no> SEE ALSO
cweave(1), perl(1), chktex, lacheck(1), ispell(1) BUGS
Doesn't even compile under Perl versions before perl v5. Unfortunately, this means that we can't even tell the user why we failed; Perl will just complain about not being able to compile the regexps. The program will try to swallow the whole input file at once, instead of processing it on a line-by-line basis. 7th Edition June 8, 1996 deweb(1)
All times are GMT -4. The time now is 10:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy