how to cut two columns in data file and print file
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ie two coloumns with one space in between two columns is required.
which CUT COMMAND is to be used.
------------------------------------------------------------------------
similarly iam having the following PRINT file .
NAME ROLL DOB
ie two columns with one space in between, which command is to be used ?
========================================================================
similarly i am having another print file of 400 pages with heading like below :
ABC COMPANY LIMITED
BRANCH OFFICE :XYZ
----------------------------------------------------
SL NO NAME OF PH DOB AGE STATUS LOAN REMARKS
-----------------------------------------------------
DATA .....
DATA .....
.........
...........
Now freinds, pl tell me with what COMMAND IN SINGLE STROKE I CAN DELETE THE HEADING IN ALL THE 400 PAGES (ie all heading like company ltd, branchoffice, slno, name,dob,age etc . i want the raw file as below
RAO,
In your first example.
Import your data into a spreadsheet application. I will assume you import your data into Open Office Calc, as it is a free application.
Once imported I will assume for each of your rows of data that the data row fills a single cell. For this explanation I will assume your data is located in cell A1 to A3. Cell A1 would have the following: 123456789rama1001
In cell B1 enter the command =LEFT(A1,13) in cell C1 enter the command =RIGHT(A1,4)
=LEFT(A1,13) this formula says to go to cell A1 and select the 13 leftmost characters
=RIGHT(A1,4) this formula says to go to cell A1 and select the 4 rightmost characters
You will get 2 columns of data that look like 123456789rama 1001. However if you click on the cells B1 + C1 you will see the formulas that you entered not the data. So the next thing you need to do is convert these formulas to values.
Highlight and Copy cell B1 and C1 to cell D1 and E1. The trick here is after you highlight and select B1 and C1 highlight cell D1 and right click to select Paste special. When the dialog box opens, in the selection area, ensure that value is selected and formula isn't selected. Click OK.
Then use the above instructions to copy this to your remaining rows of data.
If you print the data and need a space between the 2 columns of data insert a column to separate the 2 data columns.
Once that's done you'll have 2 discrete columns of data for sorting as you please.
NOTE. In your examples all the rows had the same # of characters. If each row of data is of different lengths then this will not work.
Example 2
Do the above import
in cell B1 use the same formula as above but change 13 to 5, as you only want the first 5 leftmost characters.
in cell C1 use the formula =MID(A6,7,5) This formula says go to cell A1, go over 7 characters or spaces and select the next 5 characters.
In cell D1 use the same =right formula above.
As above copy data in B1, 1 and D1 to cells E1, F1 and G1 by doing a paste special as above.
Then use the above instructions to copy this to your remaining rows of data.
Once that's done you'll have 3 discrete columns of data for sorting as you please. In your example you can either hide column F and print columns E and G or copy columns E and G to another location and print that range.
If you print the data and need a space between the 2 columns of data insert a column to separate the 2 data columns.
NOTE. In your examples all the rows had the same # of characters. If each row of data is of different lengths then this will not work.
Example 3
Do the above import
Do a global data sort.
Once the sort is done all the headings will be in one location delete those rows and resort the data as you like.
If you have to keep the data in the same order and don't want to resort the data after you sort and delete the headers.
Enter a column in the leftmost section of the spreadsheet in cell A1 insert 1, in cell A2 enter 2. Highlight cell A1 and A2, drag them to the end of you data and Calc will enter sequential numbers.
Sort this column with your data. After deleting the header rows, just sort on column A and your data will be in the original order without the headers.
First Example Solution
----------------------
For the first example above, the following works on my system from the command line:
Code:
sed -e 's/[a-z]\{1,\}/ /' filename.txt >newfilename.txt
Second Example Solution
-----------------------
For the second example above, the following works on my system from the command line:
(Note that the "+3" after "tail" is the count of lines from the beginning of the file where you want to start -- to get rid of the header.)
use command cut to separate two outputs eg: cut -c 1-9 filename > file1
cut -c 14-17 filename >file2 then use paste command as: paste -d " " file1 file2
BUT this is not better than reply from dezmond(4th reply)..
{
NAME ROLL DOB
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.