Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Basic loop awk/shell script question.. Post 302902047 by pc2001 on Saturday 17th of May 2014 08:13:33 PM
Old 05-17-2014
Hi Don,

I wish!

Okay, here's what I've go so far:
Code:
#!/bin/bash

#
# 1. Read in input file and separate out filename
# 2. Search for it
# 3. Copy it in a directory
# 4. Create file with old and new file paths

outdir=/Users/pc/test/newdata
outfile=copyDetails.txt
ofile=${outdir}/${outfile}
header="From    To"
echo "${header}" >> $ofile

while read Barcode Sampleid Other
do
        [ "$Barcode" == "barcode" ] && continue
        pattern="*${Barcode}*"
        names=`find /Users/pc/test -name "*${Barcode}*"`
        myname=`echo $names | cut -d' ' -f1`
        cp ${myname} ${outdir}
        from=$myname
        to="${outdir}/${Barcode}"
        oline=`echo ${from}"\t"${to}`
        echo ${oline} >> $ofile


done < ../data/worksheet.txt


echo "Finished"
exit 0


Not elegant, but works for the original purpose. The input file has 3 columns and the filename is in the column 'Barcode'. I am also trying to create a file that will keep a record of the origin and destination of the file. My questions:

1. The code lines:
Code:
        oline=`echo ${from}"\t"${to}`
        echo ${oline} >> $ofile

don't give a tab separated output. The '\t' is written into the file as it is. What am I doing wrong?

2. Any comments to improve the code -- I'm just beginning here...


thanks!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

basic shell scripting question

If I did indeed grep something out of it, why woudln't $result show nothing? When I do $? , it does show success... What is the proper syntax so that $result shows actual thing it's grepping out? result=`(ssh $host tail -1 /something/somethingelse) | egrep -i "value" >dev/null` #echo... (3 Replies)
Discussion started by: convenientstore
3 Replies

2. UNIX for Dummies Questions & Answers

A basic question of FOR loop

Hi, have a basic query. Please see the below code: list="one two three" for var in $list ; do echo $var list="nolist" Done Wht if I want to print only first/ last line in the list Eg one & three Regards er_ashu (3 Replies)
Discussion started by: er_ashu
3 Replies

3. UNIX for Dummies Questions & Answers

Basic awk question...getting awk to act on $1 of the command itself

I have a script problem that I am not able to solve due my very limited understanding of unix/awk. This is the contents of test.sh awk '{print $1}' From the prompt if I enter: ./test.sh Hello World I would expect to see "Hello" but all I get is a blank line. Only then if I enter "Hello... (2 Replies)
Discussion started by: JasonHamm
2 Replies

4. Shell Programming and Scripting

really basic for loop question

sorry for being dumb here, but is there a way my for loop can take an entire line of a file into consideration instead of each word in a line... ill explain if i have a file like this # cat list serial: 23124 hostname: server1 and a script that does this # cat list.sh #!/bin/sh ... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

5. Shell Programming and Scripting

Basic script question

I'm trying to approach a problem but all I'm coming up with are complex ways to manipulate the data. But still not getting the desired outcome. directory of files.... file-100-foo file-100-man file-100-chu Need to copy the files and increment the number in the file name ... (4 Replies)
Discussion started by: suphawk
4 Replies

6. Shell Programming and Scripting

Shell script / Grep / Awk to variable and Loop

Hi, I have a text file with data in that I wish to extract, assign to a variable and process through a loop. Kind of the process that I am after: 1: Grep the text file for the values. Currently using: cat /root/test.txt | grep TESTING= | awk -F"=" '{ a = $2 } {print a}' | sort -u ... (0 Replies)
Discussion started by: Spoonless
0 Replies

7. Shell Programming and Scripting

Very Basic Question regarding "while" loop

Hi, I have a loop like this - while read item do // fire insert query done < itemList.txt The itemList.txt has say, 1000 records. Now what I do is that rhough another program, I make the itemList.txt EMPTY, but still the INSERT query keeps firing the sequence of records. ... (18 Replies)
Discussion started by: angshuman_ag
18 Replies

8. Shell Programming and Scripting

Unix Shell basic loop massive n00b

hey guys I would really appreciate some help, i need to do a project for a job that requires minimal UNIX scripting and im REALLY stuck basically Im stuck at what i believe is something really simple but i just dont have a clue how to do it efficiently and properly and i REALLY appreciate some... (16 Replies)
Discussion started by: thurft
16 Replies

9. Shell Programming and Scripting

Question about a basic shell script: How to make sure it receives only one input?

Hello all! I am very new to shell and Linux in general (I just started 2 days ago), I am trying to write a script that adds the size of the directories and files in a given directory and displays messages if the user puts in something wrong. I think I have covered all the possible problems except... (3 Replies)
Discussion started by: 2358
3 Replies

10. Shell Programming and Scripting

Basic question on shell script execution

I have two shell scripts in the different directories listed below, /root/dev/dir1/test.sh /root/dev/dir2/master.sh I am executing the master.sh script from the test.sh like below and getting 'Permission denied' error. #! /bin/sh #test.sh path='/root/dev' $path/dir2/master.sh But it... (2 Replies)
Discussion started by: vel4ever
2 Replies
Barcode::IATA2of5(3)					User Contributed Perl Documentation				      Barcode::IATA2of5(3)

NAME
GD::Barcode::IATA2of5 - Create IATA2of5 barcode image with GD SYNOPSIS
ex. CGI use GD::Barcode::IATA2of5; binmode(STDOUT); print "Content-Type: image/png "; print GD::Barcode::IATA2of5->new('1234567890')->plot->png; with Error Check my $oGdBar = GD::Barcode::IATA2of5->new('A12345678'); die $GD::Barcode::IATA2of5::errStr unless($oGdBar); #Invalid Characters $oGdBar->plot->png; DESCRIPTION
GD::Barcode::IATA2of5 is a subclass of GD::Barcode and allows you to create IATA2of5 barcode image with GD. new $oGdBar = GD::Barcode::IATA2of5->new($sTxt); Constructor. Creates a GD::Barcode::IATA2of5 object for $sTxt. $sTxt has numeric characters([0-9]). plot() $oGd = $oGdBar->plot([Height => $iHeight, NoText => 0 | 1]); creates GD object with barcode image for the $sTxt specified at new method. $iHeight is height of the image. If NoText is 1, the image has no text image of $sTxt. ex. my $oGdB = GD::Barcode::IATA2of5->new('12345678'); my $oGD = $oGdB->plot(NoText=>1, Height => 20); # $sGD is a GD image with Height=>20 pixels, with no text. barcode() $sPtn = $oGdBar->barcode(); returns a barcode pattern in string with '1' and '0'. '1' means black, '0' means white. ex. my $oGdB = GD::Barcode::IATA2of5->new('12345678'); my $sPtn = $oGdB->barcode(); $errStr $GD::Barcode::IATA2of5::errStr has error message. $text $oGdBar->{$text} has barcode text based on $sTxt specified in new method. AUTHOR
Kawai Takanori GCD00051@nifty.ne.jp COPYRIGHT
The GD::Barocde::IATA2of5 module is Copyright (c) 2000 Kawai Takanori. Japan. All rights reserved. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. SEE ALSO
GD::Barcode perl v5.16.3 2003-05-29 Barcode::IATA2of5(3)
All times are GMT -4. The time now is 07:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy