LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Edit a large text file (https://www.linuxquestions.org/questions/programming-9/edit-a-large-text-file-721221/)

emclinux 04-23-2009 01:39 PM

Edit a large text file
 
This should be easy and I dont know the best way to go about this. I have a large output of an ls command. The following is a part of the output.

Code:

/mnt/lfs/oldsrc:
autoconf-2.63.tar.bz2
automake-1.10.1-test_fix-1.patch
automake-1.10.1.tar.bz2

I need to modify that to be this

Code:

/mnt/lfs/oldsrc/
/mnt/lfs/oldsrc/autoconf-2.63.tar.bz2
/mnt/lfs/oldsrc/automake-1.10.1-test_fix-1.patch
/mnt/lfs/oldsrc/automake-1.10.1.tar.bz2


zQUEz 04-23-2009 01:50 PM

assuming you have the file names in a file called /mnt/lfs/oldsrc, you could do something like:

#!/bin/bash
rm -rf /tmp/output
for LINE in `cat /mnt/lfs/oldsrc`; do
echo "/mnt/lfs/oldsrc/$LINE" >>/tmp/output
done

irishbitte 04-23-2009 01:55 PM

I think what you are looking for is actually some variation of the find or locate commands

try this:
Code:

locate auto* | grep /mnt/lfs/oldsrc
and let us know how you go.

If locate gives an error, you may not have an index database setup, in which case you need to run as root:

Code:

updatedb
be careful with updatedb, it will run for a fair period of time if you have a large filesystem ~100GB or so in size.

Let us know how you get on.

The post from zQUEz looks good too!

emclinux 04-23-2009 02:04 PM

I got the file by running
Code:

ls -AR /mnt/lfs/ > testing.out
Basically what I need is a list of every directory and file on the system. I was able to produce it using the command but it needs some editing. I really cant do it by hand because it is 34,384 lines long.

druuna 04-23-2009 02:31 PM

Hi,

Wouldn't this be a better(?) solution: find /mnt/lfs/

The 'only' difference between your desired output and that of the find command: You show a / after each dir (/mnt/lfs/oldsrc/ vs /mnt/lfs/oldsrc).

ntubski 04-23-2009 02:45 PM

Quote:

The 'only' difference between your desired output and that of the find command: You show a / after each dir
Which can also be accomplished with find:
Code:

find /mnt/lfs -type d -printf '%p/\n' -o -print

vikas027 04-24-2009 05:10 AM

Quote:

Originally Posted by ntubski (Post 3518799)
Which can also be accomplished with find:
Code:

find /mnt/lfs -type d -printf '%p/\n' -o -print

Isn't this code equivalent to
Code:

find /mnt/lfs
?

I tried running this command, on my server.

Code:

[root@vikas ~]# find /tmp/ |wc -l
7636
[root@vikas ~]# find /tmp -type d -printf '%p/\n' -o -print | wc -l
7636


druuna 04-24-2009 05:13 AM

Hi,

The difference can be found in the way directories are displayed, not the amount of files found.

find /mnt/lfs will show a directory as: /mnt/lfs/usr/bin

ntubski solution will show: /mnt/lfs/usr/bin/ (mind the extra slash on the end!)

Hope this clears things up.

vikas027 04-25-2009 04:54 AM

Quote:

Originally Posted by druuna (Post 3519386)
Hi,

The difference can be found in the way directories are displayed, not the amount of files found.

find /mnt/lfs will show a directory as: /mnt/lfs/usr/bin

ntubski solution will show: /mnt/lfs/usr/bin/ (mind the extra slash on the end!)

Hope this clears things up.

Okay, will take a note of this.

Thanks


All times are GMT -5. The time now is 12:05 PM.