Unix scripting problems

Hi,
In my unix server, i received a file in /usr/data/xmit location. i want to write a unix script after file reached.
So how can i write a one line code which chceks the presence of the file? and second line line should take the status of the prevous line. like below.

Line 1: checks for the presence of file
Lein 2: STATUS=$?

test -f /usr/dat/xmit/putyourfilenamehere
STATUS=$

Thanks,
I hav one more question
in my application script, in the first line itself, below one line code is there
CONCAT_PARMS=$1\|$2\|$3\|$4
Can you tel me what it does?

Try it out, place these lines in your script:

CONCAT_PARMS=$1\|$2\|$3\|$4 
echo $CONCAT_PARMS

and call your script with 4 parameters like:

./scriptname par1 par2 par3 par4

Understood, Thnks

Note that test -f file is successful only if file is a regular file, not a symbolic link.

Also, test -e file is successful for any file, even a symbolic link.

Also, test -s file is sometimes more helpful because it fails for empty (zero-length) files (but succeeds for symbolic links).

Rather than put the result in a variable with $?, the code might be easier to read if you do it in a structured way, like this:

if [ -s /usr/dat/xmit/file ]; then
    # Do your processing here
fi

Note that the bracket, [, is the same as test.

Thnks to all.
I have one problem in my script.
in my script, i have below line of FTP code:

ftp -nv $server > $logfile <<END
 user $id $pwd
 put $fil1 $fil2
 bye
END

While i try to execute my script, it showing error like:

220  FTP server ready.
331 Password required for admin.
530 Login incorrect.
Login failed.
530 Please login with USER and PASS.
530 Please login with USER and PASS.
221 Goodbye.
$

If i give each line individually lik below,

$ ftp -nv $server
$ user $id $pwd

then FTP is happening corectly. Can anyone plz tel me wats wrong in my first FTp step by which im unable to connect?

On the surface the value in "$pwd" is not the correct password for the account "admin" on the remote server.

Hi, i have a file called sc.txt

cat sc.txt
ecf0183.sh
ecf1002.sh
ecf1011.sh
ecf1020.sh

another file callled All.csv

Type,S Name,Mem Lib,S Id,S Table,App,Group
Reg sch,ecf1002,Link from 1,pcor1,EER,ecf1002.sh,ECF-D-LND-AMZ-A
Reg sch,ecf1002a,Link from 2,pcor1,EER,ecf1002.sh,ECF-D-LND-AX-B
Reg sch,ecf1011ab,Link from 4,pcor1,EER,ecf1011.sh,EW-G-LND-AX-C
Reg sch,ecf1020rt,Link from 9,pcor1,EER,ecf1020.sh,EW-G-JYD-GEX-D

i need to take the sc.txt as a reference and need to compare with All.csv and then need to create a file as below. please help me with the code

sc              S Name    S id    Group
ecf0183.sh  NA           NA     NA
ecf1002.sh  ecf1002    pcor1 ECF-D-LND-AMZ-A
                 ecf1002a  pcor1 ECF-D-LND-AX-B
ecf1011.sh  ecf1011ab pcor1 EW-G-LND-AX-C
ecf1020.sh  ecf1020rt  pcor1 EW-G-JYD-GEX-D

try this code, this will definetely help you..

ftp -n $server > $logfile <<EOF
 user $id $pwd
 put $fil1 $fil2
 bye
END

please let me know if you get any error.

Regards
rajesh

Although the here-document tags must match.

ftp -n $server > $logfile <<EOF
...
EOF

Could someone explain what below sed command will do?

sed 's/'"$(echo '\011')"'//g'  file
sed 's/'"$(echo '\011')"'//g'  file

the expectation could have been capturing the echo command's output as pattern for sed command, in this case it print \011.

I have no idea why this can't directly be used in sed. A good example would be putting pwd command instead of an echo.

Can someone plase explain below sed commands too ?

sed -e 's/^ *//' -e 's/ *$//'
sed "$file1!d;q"<file2
sed 's/'"$(echo '\011')"'//g' file

This deletes all of the spaces, if any, at the beginning of every line:

sed -e 's/^ *//'

This portion of the same command deletes all the spaces, if any, at the end of every line:

-e 's/ *$//'

This could mean almost anything depending on what variable file1 is equal to. But !d means delete every line outside of that address range. The q quits after the first match.

sed "$file1!d;q"<file2

This is curious. '\011' is a TAB character. Modern GNU sed accepts \t for a tab character, but that wasn't so in olden days. Maybe someone had to go through that gymnastic to get a tab character into a sed expression. It looks like it would delete every tab character in the file.

sed 's/'"$(echo '\011')"'//g' file
1 Like

Can someone explain wat below set of commands do?

chkcntr=1
while [ $chkcntr -le $filcntr ]
do
  filename=`sed "$chkcntr!d;q"<filenamesCnt.txt`
  filename=`sed "$chkcntr!d;q"<filenamesCnt.txt`
  filename=`echo $filename | sed -e 's/^ *//' -e 's/ *$//'`
  chkcntr=`expr $chkcntr + 1`
done

What shell are you running this in?
When I experimented with part of it in bash, the exclamation mark (!) was expanded to trash.

Very clever bash users can use the exclamation mark to include command history in the current command. I've never learned to use it because it looks like more bother than worth. Maybe the author intended to use history. The fact that the first line inside the do-loop is repeated suggests he might have. If so, I have no idea what it does. If not, there's no point in repeating the line.

But if we assume it was not intended to be that tricky, it could be made useful by changing it:

# Replace this:
  filename=`sed "$chkcntr!d;q"<filenamesCnt.txt`
# with this:
  filename=`sed $chkcntr'!d;q'<filenamesCnt.txt`

This line removes starting and ending space characters from the filename.

  filename=`echo $filename | sed -e 's/^ *//' -e 's/ *$//'`

The line with expr could just as easily be done this way:

  ((chkcntr++))