LINUX to UNIX... changes needed?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers LINUX to UNIX... changes needed?
# 1  
Old 12-05-2010
LINUX to UNIX... changes needed?

I developed the following in LINUX:
Code:
cat monica.txt | sed 's/;;;/\n;;;/g'>  fixed.txt
csplit -f comment -n 4 fixed.txt '/;;;/' {*}

Basically, I want it to take the file monica.txt and put every instance of ;;; on a new line and put it in fixed.txt, then split fixed.txt at every instance of ;;; and put it in new files called comment0001.txt, comment0002.txt,... comment2500.txt.

Now I have a Mac and am using UNIX in the program Terminal to do the task.

However, it is not creating a new line for every instance of ;;; (instead, it just replaces ;;; with n;;;. I also tried 's/;;;/\r;;;/g' because I think Mac handles line endings differently from Windows, but this didn't put every instance of ;;; on a new line, either.

I am also getting the error "*} bad repetition count" once it gets to 18 files, when it should generate 2500. Nowhere in the file do I have curly braces, so that isn't the problem.

I would appreciate any help!

I'm operating a Mac OS X with bin/bash.

Last edited by Franklin52; 12-05-2010 at 04:52 PM.. Reason: Please use code tags
# 2  
Old 12-05-2010
Try this:
Code:
awk '
!c || /;;;/{c=sprintf("%04d",++i); close("comment" c ".txt")}
{print > "comment" c ".txt"}' monica.txt

# 3  
Old 12-05-2010
I tried this and got:

awk: illegal statement at source line 3
context is
{print > "comment" >>> c <<< ".txt"}

Does anyone know what this means and how to fix this?
# 4  
Old 12-06-2010
Quote:
Originally Posted by Franklin52
Try this:
Code:
awk '
!c || /;;;/{c=sprintf("%04d",++i); close("comment" c ".txt")}
{print > "comment" c ".txt"}' monica.txt

To me, I am getting no error but no splitting happens.

Here's my code.

Code:
echo "f1;f2;f3" | awk '/;/{c=sprintf("%02d",++i); close("out" c)} {print > "out" c}'

Code:
echo "f1;f2;f3" | awk -v i=0 '/;/{close("out"i); i++; next} {print > "out"i}'

Please let me know where I have gone wrong?
# 5  
Old 12-06-2010
Try:

Code:
cat monica.txt | tr ';;;' '\n@@' | sed 's/@@/;;;/g'

R0H0N
# 6  
Old 12-06-2010
Quote:
Originally Posted by mschpers
I tried this and got:

awk: illegal statement at source line 3
context is
{print > "comment" >>> c <<< ".txt"}

Does anyone know what this means and how to fix this?
Can you post your input file and the desired output?
# 7  
Old 12-06-2010
Quote:
Originally Posted by Franklin52
Can you post your input file and the desired output?
They are attached now. Monica.txt is the full file, and comment0001.txt and comment0002.txt are samples of desired output.

I should also mention that I don't care if the ;;; is present in the output or not.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux router help needed

hi guys. I have an Kaon router wich runs "Linux version 3.10.24-svn1480 (jskim@jake-205) (gcc version 4.4.7 (Realtek MSDK-4.4.7 Build 1459". The problem I have it is that its firmware is in early stages and has alot of things messed up. Wake on lan doesn't work without arp binding and that can... (23 Replies)
Discussion started by: apoklyps3
23 Replies

2. Shell Programming and Scripting

Linux command needed

guys im new here and i need help with some linux commands. filea has keyword on each line identity aaa bbb ccc i have following commands. egrep 'www.identity' ~/home/m3 >~/home/lopo2 wc -l file ~/home/lopo2 say lopo2 has 44 lines then output saved is identity 44 (1 Reply)
Discussion started by: ahfze
1 Replies

3. Red Hat

Installing Linux on Vmware - Help needed

Hi Friends I am trying to install linux (32 bit) on windows. so i used Oracle virtual box and Vmware player in windows and installed them. but there is no category to select Linux version 7. how to install it pls help here. (7 Replies)
Discussion started by: ded325
7 Replies

4. Homework & Coursework Questions

Linux/UNIX Bash Shell Script trouble help needed!!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 2. Shell Bash Script 3. !/bin/bash if echo no directory then mkdir -p /home/AC_Drywall elif ; then echo "$dir already exist" fi (4 Replies)
Discussion started by: TomFord1
4 Replies

5. Shell Programming and Scripting

Command needed in linux flavour OS

HI, My requirement as below Log with Error Code: Starting FeedRunner for feed: 200 Product example Items Error FeedRunner for feed: 200 Product example Items Stopping FeedRunner for feed : 200 Product example Items Feed time taken 231743 Log without Error Code: ... (0 Replies)
Discussion started by: Paulwintech
0 Replies

6. UNIX for Dummies Questions & Answers

Linux Tutorial Needed

Hi guys , I m new to linux and would like to buy some quality video tutorials . Request you to guide me any good source for programming(C,Java,VB) or linux tutorials. Tutorials should be known and good like lynda.com (5 Replies)
Discussion started by: pinga123
5 Replies

7. Programming

Help needed linux socket programming in c

Good evening everyone! :) I'm doing a small client / server application for sharing files in C, and I am trying to implement the following: The client of my application sends to the address 255.255.255.255 a message requesting a particular file.In the network there is only one server,... (1 Reply)
Discussion started by: esmeco
1 Replies

8. Shell Programming and Scripting

Linux starter help needed

:confused: hi guys i'm helping out as a lab assistant and have been told to use a linux shell script to gather assignments from the students in the class I'm helping out in. They've been told to have their assignment in a certain folder in their accounts and I'm to gather them, only problem is I... (0 Replies)
Discussion started by: jaybee
0 Replies
Login or Register to Ask a Question