Converting space to newlines and renaming files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting space to newlines and renaming files
# 1  
Old 10-23-2011
Converting space to newlines and renaming files

Hi All,

I have this code which has two problems:

Code:
find . -name '*.fil' | xargs while read page
do
cat $page | awk '{for(i=1;i<=NF;i++) print $i}' $page>$page.txt
done

find . -name '*.fil.txt' | xargs rename '.fil.txt' .fil

1. I am running this code in a directory consisting of large number of files. The code gives me error in do loop. I think I have not used xargs very well here. The error is something like:
Code:
syntax error near unexpected token 'do'

2. At the end of the code you can see I have another find command to rename the files from .fil.txt to .fil again. Is there any way to get rid of renaming in the last line so that I can get .fil files directly from the third line of my code?
Code:
cat $page | awk '{for(i=1;i<=NF;i++) print $i}' $page>$page.txt

The problem is in very large set of files, this renaming takes a lot of time. I am using Linux with BASH
# 2  
Old 10-23-2011
Try this...
Code:
find . -name "*.fil" | while read line
do 
  awk '{for(i=1;i<=NF;i++) print $i}' $line > $line.txt; 
  mv $line.txt $line 
done

--ahamed
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding files with newlines in filename

I want to use grep to find files that have newlines in the filename. For example, I have a directory where I create three files: $ touch file1 $ touch "file 2" $ touch "file > with > newlines" $ find . ./file 2 ./file1 ./file?with?newlinesI now want to pipe the find output into grep and... (4 Replies)
Discussion started by: Ralph
4 Replies

2. Shell Programming and Scripting

Help/Advise please for converting space delimited string variable to comma delimited with quote

Hi, I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file. Example of the SQL will be For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING. I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

4. Shell Programming and Scripting

Merging data horizontally with newlines in files

Hi Everyone, I have two files file1 and file2 with these contents cat file1 AAAAA 01/03/2014 04:01:23 BBBB 01/03/2014 03:03:34 CCCcc 01/03/2014 03:03:34 cat file2 1 RED 1 HHHH 1 TTTT 1 BBBBB I tried the below... (2 Replies)
Discussion started by: Aditya_001
2 Replies

5. Shell Programming and Scripting

Converting varied space delimited file to Pipedemilited

Hi all, I have source file, data looks like 12345 abc def 01 / 001200 C 2000 12345 abc def 01 / 001200 C 2500 12345 abcd def 01 / 001200 C 3500 18945 xyz pqr 01 / 009900 D 4000 5000 2800 9900 Expected ouput... (3 Replies)
Discussion started by: srk409
3 Replies

6. Shell Programming and Scripting

Converting variable space width data into CSV data in bash

Hi All, I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for. My Input data in inputfile.txt 19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
Discussion started by: vharsha
4 Replies

7. Shell Programming and Scripting

need to save the space when converting to CSV file

Hi, I have a text file with the following format. Some of the fields are blank. 1234 3456 23 45464 327837283232 343434 5654353 34 34343 3434345 434242 .... .... .... I need to convert this file to a CSV file, like 1234, ,23, ... (3 Replies)
Discussion started by: wintersnow2011
3 Replies

8. Shell Programming and Scripting

Delete newlines after every one space

Hi All, I have a file which looks like this: abc 3456 computer 3214 printer 0.9823 computer 3214 Can anyone please let me know how I can format my text like this? abc 3456 computer 3214 printer 0.9823 computer 3214 I know how to space to newlines using tr but don't know how to do... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

9. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

10. UNIX for Dummies Questions & Answers

Multiple Files Renaming with space

Hi, I need help how to renaming multiple file. The original file look like this; Test Monday.txt Test Wednesday.txt Test July.txt I have more than hundred file in the directory. How i want to rename all file to a new file name in one time? The new file maybe the same name e.g.... (13 Replies)
Discussion started by: nazri76
13 Replies
Login or Register to Ask a Question