LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 08-12-2009, 11:47 PM   #1
doug23
LQ Newbie
 
Registered: Aug 2009
Posts: 18

Rep: Reputation: 0
"grep" in C#


Hi All,

I am trying to make two changes to the block of C# code at the bottom of this page. Any help would be greatly appreciated!

1) the input files are not currently valid XML files, so I used to run the following script first. Is there anyway to replicate the exact functionality of this script in the C# code (such that as the C# app opens each file, it first performs this modification)?

Code:
while read THISFILE
do
    echo '<uspto>' > /tmp/patentconversion.xml
    cat $THISFILE \
        | grep -v '<?xml' \
        | grep -v '<!DOCTYPE' \
        | grep -v '<!ENTITY' \
	| grep -v ']>' \
        | tr '\n#&\t' ' ' \
        >> /tmp/patentconversion.xml
    echo '</uspto>' >> /tmp/patentconversion.xml
done

2) Instead of creating a separate output file for each file, how can I modify the C# code such that each additional output is appended to the first output file (i.e. all files get outputted to the same c:\code-gen\output\" + file.Name file)?

Code:
// create directory object

System.IO.DirectoryInfo dirCustom = new System.IO.DirectoryInfo(@"c:\code-gen\employees");

//use GetFiles method to get all the files in the directory

System.IO.FileInfo[] filCustom = dirCustom.GetFiles();

//create the "output" directory

System.IO.Directory.CreateDirectory(@"C:\code-gen\output");

//iterate through each file in turn, create a source and target object for each file, then pass this to the Run method

foreach (System.IO.FileInfo file in filCustom)

{
Altova.IO.Input source2Source = new Altova.IO.FileInput(@"C:\code-gen\employees" + file.Name);

Altova.IO.Output target2Target = new Altova.IO.FileOutput(@"c:\code-gen\output\" + file.Name);

MappingMapTotargetObject.Run(
source2Source,
target2Target);
}
 
  


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
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
Stupid question: if [ "$i" == `$(cat ${LOGFILESSHD} | grep "${i}" )` ] ; then frenchn00b Programming 6 05-19-2008 05:16 PM
standard grep question. "The parameter list is too long" antis Linux - General 1 07-03-2007 01:43 AM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 02:14 PM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM

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

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