Help needed in formatting script files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed in formatting script files
# 1  
Old 09-27-2010
Question Help needed in formatting script files

Hi,


Can anyone tell me how i can convert all tab spaces inside a script to 4 spaces through another script.

Also i need to find if all the quotes are matching and ended properly. Any idea whould be of great help.

Many thanks!
# 2  
Old 09-27-2010
For the first question you can do someting like:
Code:
awk -F"\t" '$1=$1' OFS="    " file

For the second question you should post the input file and the desired output.
# 3  
Old 09-27-2010
@Franklin,

Many thanks for the quick reply.
Can you please explain me what the '$1=$1' does??


For the second part,
If i give a script file that has if loops as input, the script which is formatting should be able to move the lines between if and fi by 4 spaces.


Code:
i/p:
 
if ($? eq 0 )
sdfasfsaf
asfdsafs
asdfsfd
fi
 
The output should be like
if ($? eq 0 )
   sdfasfsaf
   asfdsafs
   asdfsfd
fi


Thanks for your time!
# 4  
Old 09-27-2010
Quote:
Originally Posted by justchill
@Franklin,

Many thanks for the quick reply.
Can you please explain me what the '$1=$1' does??
It's an awk idiom to force awk to rebuild $0 with the new OFS.

With the given inputfile you could do something like:
Code:
awk '
/fi/{p=0} 
p{$0="    " $0} 
/if/{p=1}
{print}' file

If this is abracadabra to you you should have a read of:

Awk - A Tutorial and Introduction
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script needed for comparing two files

Hi, I need shell script to compare the two files based on certain fields and output should contains the required fields based on result.pls find sample input files and required output file 1 COUNT, BNG_IP,PORT,OVLAN 22 , 10.238.60.129,1/1,2009 144 , 10.238.60.129,1/1,2251 ... (5 Replies)
Discussion started by: surender reddy
5 Replies

2. Shell Programming and Scripting

Help needed in formatting the output

Hi All, Need your help in resolving the below issue. I've a file called "data.txt" with the below lines: TT: <tell://me/sreenivas> <tell://me/100> <tell://me/500> TT: <tell://me/sudheer> <tell://me/300> TT: <tell://me/sreenivas> <tell://me/200> TT:... (6 Replies)
Discussion started by: raosr020
6 Replies

3. Shell Programming and Scripting

Help needed in formatting the Output file

Hi All, Need your help in resolving the below issue. I've a file called "data.txt" with the below lines: TT: <tell://me/sreenivas> <tell://me/100> TT: <tell://me/sudheer> <tell://me/300> TT: <tell://me/sreenivas> <tell://me/200> TT: <tell://me/sudheer> <tell://me/400> ... (3 Replies)
Discussion started by: raosr020
3 Replies

4. Shell Programming and Scripting

Formatting help needed awk or sed maybe

I am executing the following command: sort file1.txt | uniq -c | sort -n > file2.txt The problem is that in file 2, I get leading spaces, Like so: 1 N/A|A8MW11 8 N/A|ufwo1 9 N/A|a8mw11 10 900003|smoketest297688 10 N/A|a9dg4 10 danny|danni 12... (5 Replies)
Discussion started by: ddurden7
5 Replies

5. UNIX for Dummies Questions & Answers

Formatting Help needed

How would i write a script which will add a following content to a file. File Before running script. acpi = 1 apic = 1 builder = 'hvm' device_model = '/usr/lib/xen/bin/qemu-dm' disk = File After running the script. acpi = 1 apic = 1 builder = 'hvm' device_model =... (5 Replies)
Discussion started by: pinga123
5 Replies

6. Shell Programming and Scripting

Formatting Help needed(Sed)

I have a file called abc.txt which has following contents. 10.180.8.231=31608 10.180.8.232=29011 10.180.8.233=31606 10.180.8.234=40501 10.180.8.235=32591 10.180.8.236=31605 10.180.8.237=30561 10.180.8.238=14231 How would i find a ip address having maximum number of ram available. Here... (2 Replies)
Discussion started by: pinga123
2 Replies

7. Shell Programming and Scripting

Little formatting help needed.

I have a following string. "machine=IFLMUD5HP0581&group1=Stop" I have created 2 variables namely machine and action. machine should contain IFLMUD5HP0581 action should contain Stop How do i write a script for the same. (7 Replies)
Discussion started by: pinga123
7 Replies

8. Shell Programming and Scripting

Output formatting help needed.

Hi guys , I have a file which contains following string.(filename tempdisplay) (location 0.0.0.0:5900) i needed to write a script which will extract the string that comes after 0.0.0.0 i.e the string :5900. I have used following method to extract the string :5900 .Is it a preferred way of... (4 Replies)
Discussion started by: pinga123
4 Replies

9. Shell Programming and Scripting

help needed in a shell script for printing files

Hi All, I am writing a shell script to print all the files in a particular folder. This script is on solaris server . I am using the lp command to send the requests . lp -d printername filename . The output I get is the request id. Is there any way I can use the request Id to determine if... (1 Reply)
Discussion started by: shahshilpa
1 Replies

10. Shell Programming and Scripting

script needed for listing files

hi, i have a the direcories like usr\clone1\heap001.txt usr\clone2\heap334.txt usr\clone3\heap8899.txt i nead a command which list all the file starting with heap*.i have to execute the command from usr directory. find command is hanging, i need some other form of script to do ... (2 Replies)
Discussion started by: jayaramanit
2 Replies
Login or Register to Ask a Question