LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-28-2014, 11:57 AM   #1
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Rep: Reputation: Disabled
:) assistance required


hi all
i want to split a file using commandline argument
i have tried
split -l 2 filename


please give your suggestions
thanks in advance

Last edited by desiretolearn; 02-04-2014 at 04:05 AM.
 
Old 01-28-2014, 12:04 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Well where are you supposed to get the value from?
 
Old 01-28-2014, 12:36 PM   #3
turnerbm125
LQ Newbie
 
Registered: Jan 2014
Posts: 1

Rep: Reputation: Disabled
assistance required :) - why not use grep?

Dear assistance required,
why not use grep (assuming you have a phrase to use as a tag):
I created a text file with 54 lines (evenOdd.txt):
- every other line had the tag "even" or "odd"
- used the following on the command line to separate "even" and "odd" lines:
cat evenOdd.txt | grep -i even > evenOnly.txt (27 lines resulted - all with "even")
cat evenOdd.txt | grep -i odd > oddOnly.txt (27 lines resulted - all with "odd")
I know this is a fairly simple example, but you get the idea.
The split command assumes you want a certain number of lines regardless of the content.
Does this help?
 
1 members found this post helpful.
Old 01-28-2014, 08:43 PM   #4
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
thanks guys
but when i execute my script
say ./abc.sh 1000 47 48
it must split the file
 
Old 01-28-2014, 11:35 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
split the file HOW ??????
50/50 ?
first 1000 lines then the rest ?
or first 64 Bits of the file ,then the rest ( this is a bit common in binary image files) ?
even / odd lines ?
How ?
 
1 members found this post helpful.
Old 01-28-2014, 11:59 PM   #6
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
First file having 2 records and last file having 5 and rest will have 1000 records each.
 
Old 01-29-2014, 12:01 AM   #7
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
i have split the first and the last file i want to split the remaining files using command line arguments
 
Old 01-29-2014, 12:43 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
what have you implemented so far?
 
Old 01-29-2014, 01:08 AM   #9
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
while {
n=0
while IFS= read -r line && [ $(( n+=1 )) -le 100 ]
do
printf "%s\n" "$line"
done
split -l1000 - outfile
} < infile > outfilea0


but i want to split it using command line values
 
Old 01-29-2014, 07:28 AM   #10
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Bash command line substitutes from within the script are:

Code:
$# - gives you the number of arguments passed to you
$1 - gives you argument number 1, like if you typed "<my-script> 1000", $1 is 1000
Try echo'ing this information:

Code:
echo "The number of arguments passed is: $#"
echo "Argument #1 is: $1"
And you can of course use the number of arguments as a loop limit value and perform tests:

Code:
if [ $# < 1 ]; then
    echo "Usage: script-name <argument>"
    exit 1;
fi
 
1 members found this post helpful.
  


Reply



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
Assistance required Laksh Linux - Laptop and Netbook 2 12-28-2008 09:50 AM
Required Assistance in Mandriva tuannie Linux - Software 6 07-06-2006 11:16 AM
assistance required v.s.sankar Linux - Certification 4 05-02-2006 08:01 AM
NVidia assistance required Hubmasterflex Linux - Hardware 9 01-27-2006 10:36 PM
Gotomail Configuration assistance required jefx Linux - Software 4 05-04-2003 09:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:38 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