LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-23-2009, 01:39 PM   #1
emclinux
Member
 
Registered: Sep 2008
Posts: 49

Rep: Reputation: 16
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
 
Old 04-23-2009, 01:50 PM   #2
zQUEz
Member
 
Registered: Jun 2007
Distribution: Fedora, RHEL, Centos
Posts: 294

Rep: Reputation: 54
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
 
Old 04-23-2009, 01:55 PM   #3
irishbitte
Senior Member
 
Registered: Oct 2007
Location: Brighton, UK
Distribution: Ubuntu Hardy, Ubuntu Jaunty, Eeebuntu, Debian, SME-Server
Posts: 1,213
Blog Entries: 1

Rep: Reputation: 88
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!

Last edited by irishbitte; 04-23-2009 at 01:56 PM.
 
Old 04-23-2009, 02:04 PM   #4
emclinux
Member
 
Registered: Sep 2008
Posts: 49

Original Poster
Rep: Reputation: 16
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.
 
Old 04-23-2009, 02:31 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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).
 
Old 04-23-2009, 02:45 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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

Last edited by ntubski; 04-23-2009 at 02:46 PM. Reason: be
 
Old 04-24-2009, 05:10 AM   #7
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Question

Quote:
Originally Posted by ntubski View Post
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
 
Old 04-24-2009, 05:13 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 04-25-2009, 04:54 AM   #9
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by druuna View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting a chunk of text from a large text file lothario Linux - Software 3 02-28-2007 08:16 AM
Edit Text file abridge Linux - Newbie 1 02-16-2007 06:00 PM
Large text file synapse Slackware 3 02-28-2006 01:21 AM
file is too large to edit ukrainet Linux - Newbie 4 02-28-2005 07:46 AM
File too large to edit ukrainet Linux - Newbie 8 01-18-2005 02:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration