No 1 answering my question... any reason ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting No 1 answering my question... any reason ?
# 8  
Old 11-01-2011
Quote:
Originally Posted by danmero
Code:
awk 'NR==FNR{x=length($0)>x?length($0):x;next}{gsub(FS,OFS);while(length($0)<x)$0=$0OFS}1' OFS=B file file

what does this code do and where should i place it or replace it?

thanks.
# 9  
Old 11-02-2011
Quote:
Originally Posted by nanochan1
what does this code do and where should i place it or replace it?

thanks.
If you look close enough both of the solutions take input a file named 'file' in case of danmero's hint or 'myFile' in my case.
Just run the solution(s) with whatever input file name you have.
Am I answer your question or misreading it?
# 10  
Old 11-02-2011
Cant this:
Code:
awk 'NR==FNR{x=length($0)>x?length($0):x;next}{gsub(FS,OFS);while(length($0)<x)$0=$0OFS}1' OFS=B file file

and this
Code:
tr ' ' '#' < myFile  | sed 's/##/ B/g;s/#/ /g'

Be simplified to this:
Code:
sed 's/ /B/g' file

and this
Code:
sed 's/  / B/g' myFile

# 11  
Old 11-03-2011
stop giving others false hope

Last edited by nanochan1; 11-03-2011 at 03:00 PM..
# 12  
Old 11-03-2011
The data you've shown below doesn't remotely resemble what you showed earlier. Smilie

What is the actual input you have and what is the actual output you want and what do they have to do with each other? And what shell are you using? Smilie

Quote:
Originally Posted by nanochan1
thanks.

so if i have a command

Code:
OIFS=$IFS
    IFS=$'\n'
    index=1
    for LINE in `cat test.txt`
    do
        fileTemp[$index]=$LINE
        let index++
    done
    seatsAvail=`echo ${fileTemp[$testNo]} | cut -f2 -d ":"`    
    seatsAvailArray=(`echo $seatsAvail | tr "  " "\n" `)
    totalSeats=${#seatsAvailArray[*]}

That's a dangerous use of backticks and useless use of cat.

This is faster and safer:

Code:
while IFS="" read LINE
do
        ...
done < filename.txt

This can be modified further, since read can do splitting by itself:

Code:
while IFS=":" read A B
do
        # $A iwill be "10", $B will be "A1 B1 D2 ..."
done < filename.txt

# 13  
Old 11-03-2011
i thought what he meant is that my "this" part of the code is wrong ?
# 14  
Old 11-03-2011
I can't see what you're even trying to do, so it's very difficult to offer suggestions.

If you answered any of the questions I asked at all, that would help a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mgetty Not Answering when Calling from Outside

Hello All, mgetty Version: 1.1.36 OS: OpenSuSE 13.1 (armv7l) Modem: Zoom 56K USB Modem Model 3095 So I've been playing with mgetty for weeks now testing dialing into the USB modem from another PC using the same modem and connecting using minicom (*minicom ---dials to---> mgetty). I had... (3 Replies)
Discussion started by: mrm5102
3 Replies

2. Shell Programming and Scripting

Perl Debug Stepping Answering Questions

I am new to perl and want to get a little better understanding of debugging code in perl. I have a perl script that has questions to be answered like: he following PERL modules are recommended: Crypt::DES Crypt::PasswdMD5 IO::Pty Net::Write::Layer2 String::CRC32 Attempt to install... (0 Replies)
Discussion started by: metallica1973
0 Replies

3. Shell Programming and Scripting

ssh -t answering automatically to the password

hi, i'm using the folowing ssh command to list the newuser "crontab' from myuser ssh -t myuser@host1 "sudo -u newuser crontab -l" this is ok but it is asking me a password. Mot de passe de myuser: The problem is that i want to answer it automatically in a shell script with the... (22 Replies)
Discussion started by: Nicol
22 Replies

4. UNIX for Dummies Questions & Answers

help - question needs answering????

hey, have been set this question at school and cannot think for the life of me how to do this. Ive thought about setuid/setgid and things like that but cant make any snese of it. Can anyone help? question reads: You have a file which has the names, email addresses, mobile numbers and sales... (1 Reply)
Discussion started by: biffa
1 Replies

5. Shell Programming and Scripting

Perl: answering automatically to install questions

Hi everybody, I have been looking for an answer to this issue both on google and on the forum, but I couldn't find anything. please help me :eek: As part of an automated (in perl) install of Solaris 9, I would like to be able to answer automaticaly to the question the installer asks.... (2 Replies)
Discussion started by: zaap
2 Replies

6. BSD

Answering posts

Hi Guys...(if anyone is out there), do these specialist posts ever get answered and do we just have to bide our time and be patient, or whats the deal (3 Replies)
Discussion started by: Gerry405
3 Replies

7. Programming

what is the exact reason ?

please refer the following 2 statements... 1) int i=1,j; j= i++ + i++; 2) int i=1,j; j=++i + ++i; how j becomes 2 and 6 for the above 2 statements respectively ??? ( i guessed j must be 3 and 5) Somebody define the exact reason please.. :( ... (2 Replies)
Discussion started by: shamal
2 Replies
Login or Register to Ask a Question