Sponsored Content
Full Discussion: Awk command in while loop
Top Forums UNIX for Dummies Questions & Answers Awk command in while loop Post 302424759 by dr.house on Wednesday 26th of May 2010 08:27:26 AM
Old 05-26-2010
How about ...

Code:
#!/bin/bash

cat in.file | while read LINE
do
  case $LINE in
    "20") echo "Choice A" >> out.file ;;
    "70") echo "Choice B" >> out.file ;;
    "80") echo "Choice C" >> out.file ;;
    *   ) echo "Crapshot" >> out.file ;;
  esac
done

exit 0
#finis

Code:
[house@leonov] bash test.bash
[house@leonov] cat out.file
Choice A
Choice A
Choice A
Choice C
Choice B
Choice B
Choice A

This User Gave Thanks to dr.house For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparison and editing of files using awk.(And also a possible bug in awk for loop?)

I have two files which I would like to compare and then manipulate in a way. File1: pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2: pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2... (1 Reply)
Discussion started by: linuxkid
1 Replies

2. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

3. Shell Programming and Scripting

Problem Using If & For loop in AWK Command

I am parsing file for the fields using awk command, first i check 26th field for two characters using substr function if it matches then using for loop on array i search 184th field for 4 chars if it matches then i print the required fields but on execution i get the error, please help...... (5 Replies)
Discussion started by: siramitsharma
5 Replies

4. Shell Programming and Scripting

For loop, awk command issue

limit.csv data -------------- 5600050 38Nhava 400077 27Bomay rate.txt data ------------- 38NhaVA 27BomaY 27Bomay below is my script: for i in `cat limit.csv` do b=`awk '{print $1}' $i` (4 Replies)
Discussion started by: p_satyambabu
4 Replies

5. Shell Programming and Scripting

If else condition inside for loop of awk command in UNIX shell scripting

Hi , Please excuse me for opening a new thread i am unable to find out the syntax error in my if else condition inside for loop in awk command , my actual aim is to print formatted html td tag when if condition (True) having string as "failed", could anyone please advise what is the right... (2 Replies)
Discussion started by: karthikram
2 Replies

6. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

7. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

8. Shell Programming and Scripting

How to use a loop for multiple files in a folder to run awk command?

Dear folks I have two data set which there names are "final.map" and "1.geno" and look like this structures: final.map: gi|358485511|ref|NC_006088.3| 2044 gi|358485511|ref|NC_006088.3| 2048 gi|358485511|ref|NC_006088.3| 2187 gi|358485511|ref|NC_006088.3| 17654 ... (2 Replies)
Discussion started by: sajmar
2 Replies

9. UNIX for Dummies Questions & Answers

Loop awk command on files in a folder

Hi, I'd like to loop an action over all files with given extension within a folder. The "main" action is: awk -F "\t" 'BEGIN{OFS="\t"}{if ($10=="S") print$0; }' input.txt > output.txt The input.txt should be every file in the folder with *.subVCF extension; and the output should be a file... (3 Replies)
Discussion started by: dovah
3 Replies

10. Shell Programming and Scripting

awk command with a loop

Dear all, I would be grateful for your help with the following. I have the following file (file.txt), which is about 10,000 lines long: ID1 ID2 0 1 0.5 0.6 ID3 ID4 0 0 0.4 0.8 ID1 ID5 0 1 0.5 0.3 ID6 ID2 1 0 0.4 0.8 The IDs in the first two columns can occur between... (12 Replies)
Discussion started by: aberg
12 Replies
AMC-ASSOCIATION-AU(1)					       Auto Multiple Choice					     AMC-ASSOCIATION-AU(1)

NAME
AMC-association-auto - automatic association between students and answer sheets for AMC multiple choice exams. SYNOPSIS
auto-multiple-choice association-auto --data project-data-dir --notes-id id --liste students-list.csv [--encodage-liste list-encoding] --liste-key key DESCRIPTION
The AMC-association-auto.pl command associates students with their answer sheet (when there are no errors from students when coding their student number and no error during data capture). See the section called "Identification of the students" from english user documentation for details. --data project-data-dir gives the directory where data files are (see for example AMC-prepare(1)). --notes-id id gives the identification string of the code provided for student numbers (command AMCcode in the LaTeX source file). --liste students-list.csv gives the students list. --encodage-liste list-encoding gives the students list file encoding (default is utf-8). --liste-key key gives the column name where to find the student number in the students list. --debug file.log gives a file to fill with debugging information. AUTHORS
Alexis Bienvenue <paamc@passoire.fr> Main author Jean Berard Translation from French Georges Khaznadar Translation from French COPYRIGHT
Copyright (C) 2008-2012 Alexis Bienvenue This document can be used according to the terms of the GNU General Public License, version 2 or later. Auto Multiple Choice 1.1.1 06/19/2012 AMC-ASSOCIATION-AU(1)
All times are GMT -4. The time now is 07:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy