Wrong programming

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wrong programming
# 1  
Old 10-27-2013
Wrong programming

This may be such a simple problem but I don't know what am I doing wrong.
The program I'm trying to do is

for pdb in $(ls *.pdb)

res=$(grep 'TYPE   2' $pdb | awk ' {print $1} ')
pos=${res/.pdb:REMARK/} > Type_List.txt


sec=$(grep 'STANDARD' $res | awk ' {print $4} ')
ls $sec >> Type_List.txt

This script is to list $pos and $sec creating a new file, both are related to many other files in the same directory (those *.pdb)

Thank you for your help Smilie

Last edited by margg; 10-27-2013 at 12:01 PM.. Reason: code tags
# 2  
Old 10-27-2013
Few suggestions:
skip ls in for loop.
awk '/TYPE   2/ {print $1}' 
awk ' /STANDARD/ {print $4} '

instead of
grep & awk .

$res will have only one value after exiting the for loop. Not sure , if that's what you want.

I appreciate, if you can post input sample and desired output .
# 3  
Old 10-27-2013
In addition to what greet_sed has already said:
for pdb in $(ls *.pdb)

is an inefficient way of implementing:
for pdb in *.pdb

If you don't show us the format of your input files (and provide a sample of one of your input files) and show us the results you are trying to obtain, we can't do much to help you.

What you have given us so far is basically: I want to create a file that is related to some other files. It isn't working. Fix it for me.

I'm afraid that we aren't omniscient enough to discern what output you want. Please help us help you!

Last edited by Don Cragun; 10-27-2013 at 06:39 PM.. Reason: Remove mistaken comment about final statement in script.
# 4  
Old 10-27-2013
This statement confuses me:
pos=${res/.pdb:REMARK/} > Type_List.txt

What do you think this is doing in the for loop?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What wrong?

oap_ret_fnc() { echo " Enter patch number you want to retract or 99 to exit\c" read ret_patch if then exit 0 else if then mv $ret_patch directory else clear echo "patch does not exist in directory." oap_ret_fnc fi fi exit 0 } oap_ret_fnc (2 Replies)
Discussion started by: cmarzan
2 Replies

2. UNIX for Dummies Questions & Answers

From iOS programming to Linux system programming

Hello. I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations: 1. Linux and iOS are UNIX-like systems, POSIX compliant. 2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies

3. Shell Programming and Scripting

Can anyone tell me what's wrong here...

Here is my code.... just want to compare column 1 and 2 of file 2 with file 1 as standard file and print file 2 all contents with matched index value stored in $8 of file 1 awk 'NR==FNR{ A=$0;B++;next} {print A?$0 FS B: $0 FS "Not-Found" }' FS="\t" file1 file2 here B is not printing if... (19 Replies)
Discussion started by: Akshay Hegde
19 Replies

4. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

5. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

6. Programming

C Programming - Hardware Programming

Can someone help me on suggesting some ways to access the memory content in RAM directly from C/C++ source code. Please provide me any book name or any URL so that I can get an exhaustive knowledge over it. If possible please give me some tips on interacting with hardwares directly through... (3 Replies)
Discussion started by: nandumishra
3 Replies

7. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

8. UNIX for Dummies Questions & Answers

what is wrong here

Hello, I have a simple script such as ----------------------------- #! /bin/sh YEAR=`date -u +%Y`; MONTH=`date -u +%m`; DAY=`date -u +%d`; DATE=$MONTH$DAY$YEAR LOGFILES=auditTrail-$DATE LOGMATCH=$LOGFILES\* ARGUM='' # find all files and write them to a file find . -name... (7 Replies)
Discussion started by: arushunter
7 Replies

9. Shell Programming and Scripting

Unix Systems Programming Vs Unix Programming

Several months ago I found a link that explained the difference between how a Unix Systems Admin would do scripting compared to what a Unix Programmer would do. It showed a basic script and then show several iterations that explained how the Systems Admin would change it to make it better. I was... (0 Replies)
Discussion started by: BCarlson
0 Replies

10. Programming

c programming or unix programming!?

i would like advice on the usbject of c programming (in the middle of reading a book on C). could i benefit more if i apply that knowledge in the unix format if i were able to, or would that take the point out of learning C, basically I want to stay away from strying too far away from unix and use... (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question